I've been trying to create an error message to show up in place of a search that will generate no results. So far I've had no luck. I tried do while which gave me an error message and I tried changing the while statement itself to an if which messed everything up. I tried printing out $searchresults to see if the problem was there all that did was double the first result number on each page.😕

$sql = "SELECT song_id, title, album, writer FROM master_list WHERE MATCH(album) AGAINST('$searchwords')ORDER BY title LIMIT $start, $display";     
$result = mysql_query($sql) or die (mysql_error()); $searchresults = $start + 1; while($row = mysql_fetch_object($result)){ echo "$searchresults) "; echo '<font size="-1">Title: '.stripslashes(htmlspecialchars($row->title)).'<br /></font>'; echo '<font size="-1">Album: '.stripslashes(htmlspecialchars($row->album)).'<br /></font>'; echo '<font size="-1">Writer: '.stripslashes(htmlspecialchars($row->writer)).'<br /></font>'; echo '<hr size="-1" />'; $searchresults++; } //} //error message if ($searchresults = 0){ echo '<font size="+1">Sorry no results found.</font>'; }

    You do a few strange things:

    1. $searchresults = $start + 1. I guess that means that it is always at least 1. But then you look if searchresults is 0, which it can't be.

    2. The if-statement is wrong. It should be if ($searchresults == 0). As you have it the if-statement will always be true, and searchresults will become 1.

    Instead you can do something like this:

    $sql = something;
    $result = something;
    if (mysql_num_rows($result) == 0) // If there is no results
    {
        echo "no results, try again";
    }
    else // There are at least one result
    {
        while ($row = mysql_fetch_object($result))
        {
            Do something
        }
    }
    

      :o I'm getting myself all mixed up. The $searchresults code is there to simply add a number before each result. I'm getting that code mixed up with the $result code as you pointed out, which is the code I need to be looking at.

        Write a Reply...