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
https://forums.phpfreaks.com/topic/169059-filtering-search-results/
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.';
    }

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.