0

我正在尝试在 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 中给出的布尔值

谁能帮我纠正这个问题?(对不起。仍然是菜鸟)

提前致谢。

4

2 回答 2

4

AND/OR如果您在查询中有多个条件,请添加,例如

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

另一方面,使用较新的连接语法,

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
于 2013-02-22T14:50:53.650 回答
0
Should be "WHERE tbl_info.id = info_id AND tbl_trainings.training='Meat Processing'
于 2013-02-22T14:52:24.433 回答