chrisuk Posted April 12, 2007 Share Posted April 12, 2007 I have a bit of a strange problem with a simple keyword search. The problem is that if you search for a keyword which only exists in one record, it will not return any results. There needs to be two or more records with the keyword in....which I really don't understand! Also, where there are more than 2 records, and I use mysql_num_rows to show say "10 records found for <whatever>" - the results shown is one less than displayed my the counter. Any ideas? here is the search code I am using, adapted from an example I found: <?php if ($search) // perform search only if a string was entered. { $search_var="%".$search."%"; $sql = "SELECT * from Issues WHERE issue_desc LIKE '$search_var' || solution LIKE '$search_var' "; $result = mysql_query($sql) or die ("error"); $row = mysql_fetch_array($result, MYSQL_ASSOC); $results = mysql_num_rows($result); extract ($row); ?> Thanks Link to comment https://forums.phpfreaks.com/topic/46712-solved-odd-keyword-search-problem/ Share on other sites More sharing options...
obsidian Posted April 12, 2007 Share Posted April 12, 2007 Your process is slightly off. Try this: <?php $result = mysql_query($sql); $count = mysql_num_rows($result); if ($count > 0) { // at least one record while ($row = mysql_fetch_array($result)) { extract($row); // Display current result here } } ?> Link to comment https://forums.phpfreaks.com/topic/46712-solved-odd-keyword-search-problem/#findComment-227570 Share on other sites More sharing options...
chrisuk Posted April 12, 2007 Author Share Posted April 12, 2007 that's sorted it! many thanks Link to comment https://forums.phpfreaks.com/topic/46712-solved-odd-keyword-search-problem/#findComment-227635 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.