Forum Moderators: coopster
For example, when I do a database search for a term I get 2 results but the $num_rows says there are 3 results.
I suspect it's because there are similar keywords within different search fields of the SQL statement. But I am stumped as to how I can change this. Any Suggestions?
-----> the code:
$result = mysql_query("SELECT wname, url, title, keywords, description, city, country, category FROM directory", $db);
$num_rows = mysql_num_rows($result);
if ($search) // perform search only if a string was entered.
{
mysql_connect() or die ("Problem connecting to Database");
$sql= mysql_query("SELECT wname, url, title, keywords, description, city, country, category FROM directory WHERE city LIKE '%$search%' ¦¦ wname LIKE '%$search%' ¦¦ title LIKE '%$search%' ¦¦ keywords LIKE '%$search%' ¦¦ description LIKE '%$search%' ¦¦ country LIKE '%$search%' ¦¦ category LIKE '%$search%' ¦¦ url LIKE '%$search%'", $db);
if ($sql)
{
echo "<b>Found <u>".$num_rows."</u> results to match search string: ".$search."</b><br><br>";
<----- End Code
I'll post the final solution when it works.
~Shane
THE SOLUTION:
------Begin Code
if ($search) // perform search only if a string was entered.
{
mysql_connect() or die ("Problem connecting to Database");
$sql= mysql_query("SELECT wname, url, title, keywords, description, city, country, category FROM directory WHERE city LIKE '%$search%' ¦¦ wname LIKE '%$search%' ¦¦ title LIKE '%$search%' ¦¦ keywords LIKE '%$search%' ¦¦ description LIKE '%$search%' ¦¦ country LIKE '%$search%' ¦¦ category LIKE '%$search%' ¦¦ url LIKE '%$search%'", $db);
$num_rows = mysql_num_rows($sql);
if ($sql)
{
echo "<b> Found <u>".$num_rows."</u> results to match search string: ".$search."</b><br><br>";
------End Code
Take it easy!
~Shane
p.s. Now onto the next post... eek