2014-01-15 50 views
0

即時嘗試選擇全部並跳過某一行。如何從表中選擇所有,並跳過某個值的某一行

這行有一些語法錯誤,我不知道我做錯了什麼。

SELECT * FROM ads WHERE bbookschool like '$data' && WHERE bbookname != 'TEST' ORDER BY time desc 

更多的代碼

$data = preg_replace ('#[^a-zA-Z0.-_% ]#i', '', $_POST['data']); 
$Result = mysql_query("SELECT * FROM ads WHERE bbookschool like '$data' && WHERE bbookname != 'TEST0160' ORDER BY time desc") 
or die (mysql_error()); 
while($row = mysql_fetch_array($Result)){ 
require 'book_ad.php'; 
$adCondition = (!empty($row['bbookname'])) ? $ad : ''; 
echo $adCondition; 
     } 

感謝。

+2

在'&& WHERE bbookname!','刪除where' –

回答

1

您需要使用WHERE只有一次:

SELECT 
    * 
FROM 
    ads 
WHERE 
    bbookschool LIKE '$data' 
    && bbookname != 'TEST' 
ORDER BY 
    `time` DESC; 

此外,設置%約$的數據,如果你想搜索包含$數據串詞:

bbookschool LIKE '%$data%' 

PS:我相信time也是reserved word,所以加上引號(`)。

0

更改查詢這一個:

SELECT * FROM ads WHERE bbookschool like '$data' AND bbookname != 'TEST' ORDER BY time desc 
0

試試這個

SELECT * FROM ads WHERE `bbookschool` like '%$data%' && bbookname != 'TEST' ORDER BY `time` desc 
+2

'喜歡%'$數據'%'不正確,用'like'%$ data%''改變 – Sal00m

0

試試這個。

SELECT * FROM ads WHERE LIKE '%$數據%' bbookschool和bbookname!= '測試' ORDER BY time遞減

相關問題