0

谢谢,非常好的解决方案,这回答了我的问题。如果我的 $sql 如下,我该如何使用您的解决方案:

$sql = "SELECT * FROM $tbl_main, $tbl_country, $tbl_members
WHERE ($tbl_main.country_id = $tbl_country.country_id) AND ($tbl_main.member_id = $theselect) ORDER BY $chosenTable.$orderby LIMIT $startpoint, $limit";

即我如何在代码中间的某个地方使用您的解决方案。

4

1 回答 1

4

您可以有条件地连接额外的条件:

$sql = "SELECT * FROM $tbl_main, $tbl_country, $tbl_members
WHERE ($tbl_main.country_id = $tbl_country.country_id)";

if(isset($theselect)) {
    $sql .= " AND ($tbl_main.member_id = $theselect)"; 
}

$sql .= " ORDER BY $chosenTable.$orderby LIMIT $startpoint, $limit";
于 2012-06-27T22:38:27.997 回答