如何从表中选择所有并跳过具有特定值的某一行

时间:2014-01-15 07:27:41

标签: php mysql

我试图选择所有并跳过一些行。

这一行有一些语法错误,我不知道我做错了什么。

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;   
         }

感谢。

4 个答案:

答案 0 :(得分:1)

您只需使用WHERE一次:

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

另外,如果要在$ data中搜索包含字符串的单词,请在$ data周围设置%

bbookschool LIKE '%$data%'

PS:我相信time也是reserved word,所以在它周围加上引号(`)。

答案 1 :(得分:0)

更改此查询:

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

答案 2 :(得分:0)

试试这个

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

答案 3 :(得分:0)

试试这个。

SELECT * FROM ads在哪里bbookschool喜欢'%$ data%'和bbookname!=' TEST' ORDER BY time desc