我希望SELECT
表中的某些行,但这些行必须满足column = value
之类的条件。这是我的SELECT
声明:
$query = "SELECT t1.title, t1.introtext, t2.jr_street, t2.jr_city,
t2.jr_state, t2.jr_postalcode, t2.jr_country, t3.created, t3.name,
t3.title, t3.comments, t4.ave
FROM $table1 t1
LEFT OUTER JOIN $table2 t2 ON t1.id = t2.contentid
LEFT OUTER JOIN $table3 t3 ON t1.id = t3.pid
LEFT OUTER JOIN $table4 t4 ON t1.id = t4.reviewid
";
我尝试在WHERE
语句之后添加FROM
子句,但是我收到了SQL语法错误。
答案 0 :(得分:1)
似乎我必须猜测你的问题。下次你应该给我们一个完整的例子一个确切的错误。你尝试过这样的事吗?
$value = (int) $_POST['value'];
$query = "SELECT t1.title, t1.introtext, t2.jr_street, t2.jr_city, t2.jr_state,
t2.jr_postalcode, t2.jr_country, t3.created, t3.name, t3.title,
t3.comments, t4.ave FROM $table1 t1
LEFT OUTER JOIN $table2 t2 ON t1.id = t2.contentid
LEFT OUTER JOIN $table3 t3 ON t1.id = t3.pid
LEFT OUTER JOIN $table4 t4 ON t1.id = t4.reviewid
WHERE t2.column = ".$value."
AND t1.catid=8";
我猜你要从table2中选择;)你必须填写正确的表和列。此外,我将类别选择放在where子句中,因为imho这使它更具可读性。
请确保保存所有变量,例如$value
(和表),以便在查询中使用,例如$value
是一个整数,表格在您的代码中明确设置不是用户输入。您可以在此处阅读有关SQL注入的更多信息: