I would not throw an exception! I will not go into exceptions, but this is bad advice. Below is one possible solution: $returned_rows = mysql_num_rows ($query); if ($returned_rows == 0){ echo 'No records found'; }else{ // process rows here }
I have another code in there, which makes it even more confusing. I don't know how to order the codes. // connection mysql_select_db("//database"); $search=$_GET["search"]; if (isset($_GET['Submit'])) { $result = mysql_query("SELECT * FROM Blog WHERE Title LIKE '%$search%'"); while($r = mysql_fetch_array($result)) { $title=$r["Title"]; $text=$r["text"]; $date=$r["date"]; echo "$title $date $text"; } } else { echo "// my blog content" } PHP:
mysql_select_db("//database"); $search=$_GET["search"]; if (isset($_GET['Submit'])) { $result = mysql_query("SELECT * FROM Blog WHERE Title LIKE '%$search%'"); $num = mysql_num_rows($result); if ($num == 0) { echo "No records found."; } else { while($r = mysql_fetch_array($result)) { $title=$r["Title"]; $text=$r["text"]; $date=$r["date"]; echo "$title $date $text"; } } } else { echo "// my blog content" } PHP: