Select * FROM book WHERE 1=1 AND text_data IN ( '%john%', '%cat%', '%dog%' ) GROUP BY chapter HAVING SUM(CASE WHEN text_data LIKE '%john%' THEN 1 ELSE 0 END) > 0 AND SUM(CASE WHEN text_data LIKE '%cat%' THEN 1 ELSE 0 END) > 0 AND SUM(CASE WHEN text_data LIKE '%dog%' THEN 1 ELSE 0 END) > 0 Code (markup): This select statement isn't printing any results. $result = mysql_query($sql) OR exit( 'Error: ' . mysql_error() ); while($row = mysql_fetch_array($result)){ echo $row['book_title']; } mysql_close($con); PHP:
Can you tell us what's in your book table? The complete row's information, or at least the text_data columns.
He's not saying it's erroring at all, he's saying that it's just returning an empty set. The SELECT is not selecting anything which means the stuff in his table does not meet all the conditions of the query.
you can try sql: Select * FROM book WHERE 1=1 AND text_data IN ( 'john', 'cat', 'dog' ) GROUP BY chapter HAVING SUM(CASE WHEN text_data LIKE '%john%' THEN 1 ELSE 0 END) > 0 AND SUM(CASE WHEN text_data LIKE '%cat%' THEN 1 ELSE 0 END) > 0 AND SUM(CASE WHEN text_data LIKE '%dog%' THEN 1 ELSE 0 END) > 0
Ok. I have a database of a chapter field a verse field and a text field: by looking at the text data, let's say I'm looking for the keywords: blablabasasda and sdcj. Looking at chapter 2 blablabasasda is found but not sdcj. So that chapter is disregarded. But in chapter 1 since words keywords are found then Chapter 1 is taken into account.
It could be no matched row What if you execute this? //$result = mysql_query( ...etc...) echo mysql_num_rows($result); PHP: