Jump to content

filtering search results


Ramtree

Recommended Posts

i have a page where the user types in what he wants to search for. then there will a code where it fetches the results from the database base on what the user wants to search for.

 

SELECT ath_id_no, name, gender, photo, country, flag, sport, COUNT(ath_id) 
FROM athlete
JOIN vote
ON athlete.ath_id_no= vote.ath_id AND sport='$_POST[filter_sport]'
GROUP BY ath_id

 

if the user tries to search for something that doesn't exist in the database, i want to display something like "no search results found"

 

i was thinking of something like


while($row=mysql_fetch_array($results))
{
if(empty($row['name']))
{
echo "no search results found";
}

else
{
echo "<td>" . $row['name'] . "</td>";
}

}

 

this doesn't work...

i thought i could check if $row['name'] is empty, since nothing is displayed on the table when the user tries to search for something that does not exist in the database.

anyone has any idea how to do this?

Link to comment
Share on other sites

Something like this should work.

 

 
$results = mysql_query("
SELECT ath_id_no, name, gender, photo, country, flag, sport, COUNT(ath_id)
FROM athlete
JOIN vote
ON athlete.ath_id_no= vote.ath_id AND sport='$_POST[filter_sport]'
GROUP BY ath_id
");

if (mysql_num_rows($result)){
        while($row=mysql_fetch_array($results)){
        echo "<td>" . $row['name'] . "</td>";
        }
    }else{
        echo 'No results were found.';
    }

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.