Jump to content

[SOLVED] odd keyword search problem


chrisuk

Recommended Posts

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

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
  }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.