Jump to content

[SOLVED] Search doesn't return multiple entries


graham23s

Recommended Posts

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
    ## 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

Link to comment
Share on other sites

Hi Barand,

 

yeah i see what you mean the thing is if only i was in the database say:

 

graham23s (if i searched graham i would get a result back)

 

if another user joined say:

 

graham24s (it would say no results even though there clearly is 2)

 

could it be somehting with the search query i have missed out?

 

thanks mate

 

Graham

Link to comment
Share on other sites

no, it's something wrong with your conditional:

 

if(mysql_num_rows($search_result) != 1) {

 

that will trigger an error if the number of rows return is anything other than 1.  this is true of any number greater than 1.  change your conditional to only trigger the error if the number of rows returned is 0:

 

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.