我想从我的表people
(MySQL)中选择数据,但仅限于朋友不为空的地方:
$sql = "SELECT * FROM people WHERE friend = '$friend' ORDER BY id ASC AND WHERE friend IS NOT NULL;" ;
我试着像这样写,但它不起作用。在这种情况下,它什么都不做。
答案 0 :(得分:1)
SELECT * FROM people WHERE friend!='' ORDER BY id ASC
答案 1 :(得分:1)
您的SQL格式错误:
$sql = "SELECT * FROM people
WHERE friend = '$friend' AND friend != ''
AND friend IS NOT NULL
ORDER BY id ASC";
据说,当$ friend没有价值时,听起来你根本不想查询:
if ($friend) {
$sql =... etc.
} else {
// No query, $friend had no value
}
你真的想确保你的数据库尽可能干净(假设你现在可以,并确保你没有插入空字符串。