Mysql query error
How do i make this code not to give error if he query is empty?
$ititle = 'test5';
$query = mysql_query("SELECT title, url, MATCH (title, url) " .
"AGAINST ('test5') AS score FROM interlinks " .
"WHERE MATCH (title, url) AGAINST (开发者_运维知识库'test5') " .
"AND title <> 'test5' LIMIT 20");
while ($irow = mysql_fetch_assoc($query) || )
{
echo $irow["title"];
echo '<br />';
}
TY!
Remove the ||, so it will just output nothing if the query is empty. It hould not give an error, other than a syntax error.
You've got a syntax error in your code: You have an OR operator (||) but nothing coming after it.
Also, look into using mysql_num_rows() to check if your query has any results before looping (though it is perfectly fine to loop without the check--you will never get inside of the loop).
精彩评论