Jump to content

No Data


Dysan

Recommended Posts

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);
?>

Link to comment
https://forums.phpfreaks.com/topic/83702-no-data/
Share on other sites

<?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);
?>

Link to comment
https://forums.phpfreaks.com/topic/83702-no-data/#findComment-425870
Share on other sites

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.