MySQL Search Query Only Returns 1 Row

Discussion in 'Databases' started by scottlpool2003, Sep 13, 2012.

  1. #1
    I've checked that there are more than 1 entry in the db, tried searching vowels, matching text etc it still only returns 1 row. I changed the query to output the array rather than the items from the db and still only 1 row?? If I change the query to limit by 1 and sort by ASC/DESC it pulls out a different item?

    <?php
    
    //Get publication info
    
    $search_term_esc = AddSlashes($searchstring);
    
    	$result = mysql_query("SELECT id,title,text,tags FROM publication WHERE title LIKE '%$search_term_esc%'");
    
        $query2 = mysql_fetch_assoc($result);
    
    
    
    print_r($query2);
    
    
    ?>
    PHP:
    Returns:

    Array ( [id] => 1 [title] => Publication Title [text] => Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. [tags] => publication, read this publication online, read publications online )
    PHP:
     
    Solved! View solution.
    scottlpool2003, Sep 13, 2012 IP
  2. #2
    You have to loop through the results.

    This: $query2 = mysql_fetch_assoc($result);

    Should be:

    
    while($query2 = mysql_fetch_assoc($result)) {
    print_r($query2);
    }
    
    PHP:
     
    jestep, Sep 13, 2012 IP