php mysql print problem

Discussion in 'PHP' started by gilgalbiblewheel, Sep 22, 2008.

  1. #1
    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:
     
    gilgalbiblewheel, Sep 22, 2008 IP
  2. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Can you tell us what's in your book table? The complete row's information, or at least the text_data columns.
     
    zerxer, Sep 22, 2008 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    Never use numbers for attributes, always make them descriptive.

    Peace,
     
    Barti1987, Sep 22, 2008 IP
  4. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Maybe try mysql_query("$sql") ?
     
    ads2help, Sep 23, 2008 IP
  5. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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.
     
    zerxer, Sep 23, 2008 IP
  6. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #6
    oh i see, sorry bout that.. =D
     
    ads2help, Sep 23, 2008 IP
  7. minghuhuang

    minghuhuang Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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
     
    minghuhuang, Sep 23, 2008 IP
  8. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #8
    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.
     
    gilgalbiblewheel, Sep 23, 2008 IP
  9. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #9
    It could be no matched row :confused:

    What if you execute this?
    
    //$result = mysql_query( ...etc...)
    echo mysql_num_rows($result);
    
    PHP:
     
    xrvel, Sep 24, 2008 IP