Dysan Posted December 30, 2007 Share Posted December 30, 2007 I have the following code, that outputs Firstnames and Lastnames from a table inside a database. How do I display a message if the database/table contains no Firstnames and Lastnames? <?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die(mysql_error()); } mysql_select_db("db", $con); $result = mysql_query("SELECT * FROM person"); while($row = mysql_fetch_array($result)) { echo $row['FirstName'].'<br />'; echo $row['LastName'].'<br />'; } mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/83702-no-data/ Share on other sites More sharing options...
tibberous Posted December 30, 2007 Share Posted December 30, 2007 <?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die(mysql_error()); } mysql_select_db("db", $con); $result = mysql_query("SELECT * FROM person"); if(mysql_num_rows($result)){ while($row = mysql_fetch_array($result)) { echo $row['FirstName'].'<br />'; echo $row['LastName'].'<br />'; } } else { echo "A Hax0r St0l3 0ur Namez!!!!"; } mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/83702-no-data/#findComment-425870 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.