SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Search doesn't return multiple entries

    Hi Guys,

    with the search the way i have coded it, it won't bring back multiple entries if i search for members say:

    graham23s

    it brings the result back fine if 2 members join sat

    graham23s
    graham24s

    it says no entries found, it then no longer gets the initial first entry (even though i loop the results out)

    heres the search code:

    PHP Code:
    <?php
        
    ## search trailers ##################################################################
        
    if ($_GET['action'] == "search") {
        
        
          if(isset(
    $_POST['search'])) {
          
          echo 
    '<br /><center><h4>Search Results</h4></center>';
          
          
    ## now do the search ##############################################################
          
    $keywords CleanPosts($_POST['keywords'], 1);
          
          if(empty(
    $keywords)) {
         
            echo 
    '<br /><font color="red" /><b>Error:</font> Sorry, You Never Typed In A String To Search For!<br /><br />';
            include(
    "includes/footer.php");
            exit;
         
          }      
          
         
    ## now do the search.../////////////////////////////////////////////////////////////
         
    $search_query "SELECT * FROM `trailers` WHERE (`name` LIKE '%$keywords%')";
         
    $search_result mysql_query($search_query) or die (mysql_error()); 
          
          
    ## any results ####################################################################
         
    if(mysql_num_rows($search_result) != 1) {
         
         echo 
    'Sorry, We Found No Search Results For (<font color="red">'.$keywords.'</font>)<br /><br />';
         include(
    "includes/footer.php");
         exit;
         
         } else {
         
         
    ## echo table ######################################################################
         
    echo 'Displaying Search Results For (<i><tt><font color="red" /><b>' .$keywords'</b></font></tt></i>)<br /><br />';
         echo 
    '<table width="60%" border="1" bordercolor="#000000" cellpadding="3" cellspacing="0" />
               <tr>
               <th width="10%" bgcolor="#004E98"><font color="#ffffff">ID</font></th><th width="50%" bgcolor="#004E98"><font color="#ffffff">Movie Name</font></th>
               </tr>'
    ;
         
         while(
    $row_search mysql_fetch_array($search_result)) {
         
         
    $trail_id $row_search['id'];
         
    $trail_name $row_search['name'];
         
    $trail_link $row_search['link'];
         
         echo 
    '<tr><td>'.$trail_id.'</td><td><a href="'.$trail_link.'">'.$trail_name.'</a></td>';
         
         } 
    // end while
         
         

         
            echo 
    '</table><br />';
                      
            include(
    "includes/footer.php");
            exit;
            
          } else {
    ?>
    i have no idea whats goin on any help would be great

    cheers

    Graham

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You wrote your condition to exit the script if the number of results is not exactly 1.

    PHP Code:
    if(mysql_num_rows($search_result) != 1) { 

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
      if(mysql_num_rows($search_result) != 1) { 
    That line treats finding 2 results like no results!

    If the number of results is not equal to one ... show failure.

    How about if you change it to just:

    PHP Code:
      if( mysql_num_rows($search_result) ) { 
    Not sure if thats the exact answer to your probs, but it jumped out at me.
    Last edited by Cups; Jul 19, 2007 at 12:58. Reason: OOOhhh too slow ...

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    How about if you change it to just:

    PHP Code:
      if( mysql_num_rows($search_result) ) { 
    Not sure if thats the exact answer to your probs, but it jumped out at me.
    Since this is the failure condition, you need the opposite. Changing the 1 to a 0 in the original condition would work.

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Yep, Dans right.

    Should read:

    if( mysql_num_rows($search_result) ==0 ) {


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •