dongpo1216 2017-01-29 05:27
浏览 93

将PHP解析为HTML样式参数

I want to make the style parse from the information given in the query.

I have the bgcolor & text color that I want displayed listed in my table, and I have tested the MySQL query and it runs fine, but I've tried to get it to run here but it does not provide me with what I need.

The way I tried was this:

<?php
include('SQLFunctions.php');
$q = $_POST["q"];
$link = f_sqlConnect();
$ATColor = 'SELECT M.ATeam, T.bgcolor,T.txtcolor 
FROM matches M LEFT JOIN teams T ON M.ATeam=T.TeamID WHERE MatchID = '.$q;

if($result = mysqli_query($link,$ATColor)) {
while ($row = mysqli_fetch_array($result)) {
echo "<th colspan='2' style='background-color:{$row[1]};color:{$row[2]}'><p>$ATeam</th>"; }
} else {
echo "<th colspan='2'><p>$ATeam</p></th>";
}

On this I get the false side displayed, It clearly is an issue with the first 2 lines of the if statement, but I can't see the issue. The $link is a global string and works everywhere else, so it's not that.

Appreciate someone pointing out somethings that's probably easy & obvious.

UPDATE:

After lots of testing it's certainly to do with the if statement, but I cannot see the issue.

  1. If I run a var_dump($result) I get nothing, showing why it's going to the false side.
  2. I have checked the two strings, $link is used to connect the entire page, so is definitely working, $ATColor can be correctly parsed on the false side, and correctly gives the MySQL query, which works perfectly if entered into CLI.
  3. Just to ensure my query had nothing wrong, I changed it to a simple SELECT * FROM matches; it still goes to the false side.

So I have no idea why, there are no errors on the page (I have error reporting on) and the code loos fine.

These two lines are somehow the issue, please help, it's driving me crazy:

if($result = mysqli_query($link,$ATColor)) {  
              while ($row = mysqli_fetch_array($result)) {
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料