WHERE子句错误

时间:2013-02-22 14:49:32

标签: php html mysql sql

我正在尝试在HTML表格中的数据库中显示特定值。声明是这样的:(这只是一个例子)

$sql = "SELECT * FROM tbl_trainings WHERE tbl_trainings.training='Meat Processing'";

我的问题是我有这个陈述(加入表格):

$sql="SELECT 
tbl_info.id, 
tbl_info.firstname, 
tbl_info.middlename, 
tbl_info.lastname, 
tbl_trainings.id,
tbl_trainings.training,
tbl_trainings.info_id
  FROM tbl_info, tbl_trainings
  WHERE tbl_info.id = info_id 
  ORDER BY tbl_info.id";

我正在尝试在语句中插入WHERE tbl_trainings.training='Meat Processing',如下所示:

$sql="SELECT 
tbl_info.id, 
tbl_info.firstname, 
tbl_info.middlename, 
tbl_info.lastname, 
tbl_trainings.id,
tbl_trainings.training,
tbl_trainings.info_id
  FROM tbl_info, tbl_trainings
  WHERE tbl_info.id = info_id, tbl_trainings.training='Meat Processing'
  ORDER BY tbl_info.id";

但是我收到了错误。错误是:

警告:mysql_fetch_array()要求参数1为资源,在C:\ wamp \ www \ CLphpTest \ meatproc.php中给出布尔值

有人可以帮我纠正这个吗? (我很抱歉。还是一个菜鸟)

提前致谢。

2 个答案:

答案 0 :(得分:4)

如果您在查询中有多个条件,请

添加AND/OR,例如

WHERE tbl_info.id = info_id AND
      tbl_trainings.training='Meat Processing'

作为一方而不是,使用更新的join语法

SELECT  tbl_info.id,
        tbl_info.firstname,
        tbl_info.middlename,
        tbl_info.lastname,
        tbl_trainings.id,
        tbl_trainings.training,
        tbl_trainings.info_id
FROM    tbl_info
        INNER JOIN tbl_trainings
            ON tbl_info.id = tbl_trainings.info_id
WHERE   tbl_trainings.training = 'Meat Processing'
ORDER   BY tbl_info.id

答案 1 :(得分:0)

Should be "WHERE tbl_info.id = info_id AND tbl_trainings.training='Meat Processing'