douzhang7603 2015-06-04 19:45
浏览 38

需要选择该行中的特定行和特定列,并将其与php变量进行比较

This is my block of code for doing that. It works fine until it reaches the last if statement. I cannot get it to find the Graphics column using the Department_ID. I am trying to check if the user input is equal to a id within the table. Then check if that id requires graphic work done. To do that, I need to find out that for that specific project graphic is a 1 in the database.

if($graphics_id != Null)
{   
    $query = mysqli_query($connect,"SELECT * FROM Project_Overview WHERE Project_ID='".$graphics_id."'"); 
    $row = mysqli_fetch_assoc($query);
    //echo $row['Project_ID'];

    if($graphics_id == $row['Project_ID']) //if the graphics_id matches a project_id in the table
    {
        $result =  mysqli_query($connect, "SELECT Graphics FROM Department WHERE Department_ID ='".$graphics_id."'")
        $row = mysqli_fetch_assoc($result);

        if($result)
        {
            echo $row['Department_ID'];
        } else {
            echo "This Project does not require graphics!"
        }   
    } else {
        echo "Project_ID ".$graphics_id." does not exist!";
    }       
}
  • 写回答

1条回答 默认 最新

  • dongwo8827523 2015-06-04 20:34
    关注

    A few thoughts:

    • The second SELECT Statement selects the Graphics column, but later you are echoing $row['Department_ID']; which should be empty as the only key in $row would be Graphics
    • The last if-Statement is if($result). Don't you mean if($row)? If $result is false (and hence "This Project does not require graphics!" is printed out), this would indicate, that mysqli_query has failed, possibly because of an error in your second SQL statement.
    • And, as ThomasEllis said, a JOIN would be nicer and SELECT * is not wrong but returns (probably) more than you need.
    • Depending on where $graphics_id comes from (a user input?) you should consider escaping it for security reasons ($graphics_id_escaped = mysqli_real_escape_string($connect, $graphics_id); - just in case ;)
    评论

报告相同问题?

悬赏问题

  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致