gpt4 book ai didi

php - WHERE 子句错误

转载 作者:太空宇宙 更新时间:2023-11-03 11:01:50 27 4
gpt4 key购买 nike

我试图在 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 中给出的 bool 值

谁能帮我改正这个问题?(对不起。还是菜鸟)

提前致谢。

最佳答案

如果您在查询中有多个条件,请添加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

关于php - WHERE 子句错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15026796/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com