Jump to content

else { echo not working at the end of a table


mattc_uk

Recommended Posts

Please help, when I run this search and enter something in the search thats not in the database, it doesnt reply with "Your query returned 0 results" as it should. I tjust stays blank

 

Here's the section of code in question...

 

if ($search)   // perform search only if a string was entered. 
   { 
    mysql_connect($host, $user, $pass) or die ("Problem connecting to Database"); 

    $srch="%".$search."%";

    $query = "select * from tvads WHERE advert LIKE '$srch' ORDER BY advert, year DESC, details ASC LIMIT 0,30"; 

    $result = mysql_db_query("cookuk_pn", $query); 

    if  ($result) 
    { 

   $count = 1;   

   print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"  bordercolor=\"#0000FF\" width=\"900\">";
   print "<tr><td width=\"200\" height=\"30\" align=\"left\"><u><b><font face=\"arial\" size=\"2\" color=\"#800080\">Advert / Description</font></b></u></td>";
   print "<td width=\"80\" align=\"left\"><u><b><font face=\"arial\" size=\"2\" color=\"#800080\">Year</font></b></u></td>";
   print "<td width=\"200\" align=\"left\"><u><b><font face=\"arial\" size=\"2\" color=\"#800080\">Artist</font></b></u></td>";
   print "<td width=\"200\" align=\"left\"><u><b><font face=\"arial\" size=\"2\" color=\"#800080\">Track</font></b></u></td>";
   print "<td width=\"80\" align=\"left\"><u><b><font face=\"arial\" size=\"2\" color=\"#800080\">Buy Album</font></b></u></td>";
   print "<td width=\"100\" align=\"left\"><u><b><font face=\"arial\" size=\"2\" color=\"#800080\">Download MP3</font></b></u></td></tr>";

        while ($row = mysql_fetch_array($result)) {     // Begin while 


$data .= "<td width=\"200\" height=\"30\" align=\"left\"><font face=\"arial\" size=\"1\">" .$row['advert']. "</font><br>";

$data .= "<font face=\"arial\" size=\"1\" color=\"#000080\"><i>" .$row['details']. "</i></font></td>";

$data .= "<td width=\"80\" height=\"30\" align=\"left\"><font face=\"arial\" size=\"1\">" .$row['year']. "</font></td>";

$data .= "<td width=\"200\" height=\"30\" align=\"left\"><font face=\"arial\" size=\"1\">" .$row['artist']. "</font></td>";

$data .= "<td width=\"200\" height=\"30\" align=\"left\"><font face=\"arial\" size=\"1\">" .$row['track']. "</font></td>";

$data .= "<td width=\"80\" height=\"30\" align=\"left\"><font face=\"arial\" size=\"1\">" .$row['asin_ref']. "</font></td>";

$data .= "<td width=\"100\" height=\"30\" align=\"left\"><font face=\"arial\" size=\"1\">" .$row['mp3_ref']. "</font></td></tr>";

$count++;

        }                  // end while 
        $data .="</table>"; 
   echo $data;
     } else { echo "problems...."; } 
   } else { echo "Your query returned 0 Results"; } 
?> 

Because the logic is if($search) { , as long as the variable $search has a value, the else{} will not be reached. You need to check how many results the query actually returns in order to determine whether to echo the message or not.

the last else only shows if no search term was entered.  Try this.

$result = mysql_db_query("cookuk_pn", $query);
    if(mysql_num_rows($result)==0) {
        echo "Your query returned 0 Results";
   }

    else if  ($result)
    {
         echo "Your output."
    }

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.