开发者

Can you have an OR in a WHERE statement inside a mysql query?

Is it possible to have an OR inside a WHERE statement in a mysql query as I have done below.

$query = mysql_qu开发者_高级运维ery("SELECT * FROM fields WHERE post_id=$id OR post_id="" order by id desc") or die(mysql_error());

This produces a server error when run on my site. Any thoughts on how I could accomplish this?

Thanks in advance.


Yes you can have an OR. What is the type of post_id?

If post_id is a character type:

"SELECT * FROM fields WHERE post_id='$id' OR post_id='' order by id desc"

If it's an integer then it can't be equal to the empty string. Did you mean post_id IS NULL instead?


What is the error? It looks like you have not escaped the double quote in the query. It should be:

$query = mysql_query("SELECT * FROM fields WHERE post_id=$id OR post_id=\"\" order by id desc") or die(mysql_error());


what are the errors.. as such ur query is fine but u string problems with all these double quotes.. try something like this..

$query = mysql_query("SELECT * FROM fields 
           WHERE post_id = " . $id . " OR post_id='' order by id desc") 
         or die(mysql_error());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜