what i am tring to do it to show a catalog with php and stop php from displaying any data to the cusomer if table does not have any information it.

for example i want to use if state ment to stop and skip if data in the database table does not exist:

$query = "SELECT * FROM Harrow_VH";
$result = mysql_query($query)
	or die("Info on your zipcode not found");

if (no data in table exit show this)
{
}
else
{
//if data in db exist then i would display it
}

basically i need to know what i would use in the if statements to stop it from the data base info.
I am bit new to PHP and !result would not work because i think the data in result is set to 1 if there is data in table o not.

Try something like this:

if (!$res = mysql_query($sql)) {
echo mysql_error();
exit();
}
if (mysql_num_rows($res) > 0) {
while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
	echo "<br />".$row['zipcode'];
}
} else {
echo "No data.";
}

It works but dont think so that we need the top if statement.
Thanks a lot

It's called good programming. Yes, the program will work without using the if statement. However, if you create a bad SQL statement or have some other error, you won't know it and the error will dump to your user. The top line with the if statement is a method called "error trapping", and is a hallmark of good programming architecture. Any line in your code that has potential for errors should be handled in such a way that your program can gracefully exit from the error condition.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.