graham23s Posted July 19, 2007 Share Posted July 19, 2007 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted July 19, 2007 Share Posted July 19, 2007 And you enter what, exactly, in the keywords field? What do you get if you enter "ham", say? Quote Link to comment Share on other sites More sharing options...
graham23s Posted July 19, 2007 Author Share Posted July 19, 2007 Hi Barand, i have tried allsorts gra,ham if there was only 1 result it would bring it back, soon as there 2 its says no results found! i cant work it out cheers Graham Quote Link to comment Share on other sites More sharing options...
Barand Posted July 19, 2007 Share Posted July 19, 2007 Entering "gra,ham" will not work as you query is looking for records containing that exact string somewhere in the name. It would only work if the names were gra,ham23s gra,ham24s Just entering "graham", or "ham" as I suggested, should find your records Quote Link to comment Share on other sites More sharing options...
graham23s Posted July 19, 2007 Author Share Posted July 19, 2007 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 Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 19, 2007 Share Posted July 19, 2007 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) { Quote Link to comment Share on other sites More sharing options...
graham23s Posted July 19, 2007 Author Share Posted July 19, 2007 Thanks mate, that did the trick alright:) Graham Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.