...

View Full Version : Is table empty?



timgolding
11-13-2007, 11:48 AM
Hi I have a MySQL database and a script that get data from a table



<?PHP
$query = sprintf("SELECT * FROM courses",
mysql_real_escape_string($code));
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result))
{
$index=$row['code'];
$stack[$index]['title']=$row['title'];
$stack[$index]['description']=$row['description'];
$stack[$index]['level']=$row['level'];
$stack[$index]['code']=$row['code'];
$stack[$index]['active']=$row['active'];
}
?>


This works fine. What I need to be able to do is have the script tell me if the table was empty so I don't attempt to render an empty html representation. Is this possible without the aid of an additional query?

nikos101
11-13-2007, 01:45 PM
$query = sprintf("SELECT * FROM courses",
mysql_real_escape_string($code));
$result = mysql_query($query);
$numrows = mysql_num_rows($result )or die("Error retrieving number of rows in groups table.");


if($numrows > 0) {

while ($row = mysql_fetch_assoc($result))
{
$index=$row['code'];
$stack[$index]['title']=$row['title'];
$stack[$index]['description']=$row['description'];
$stack[$index]['level']=$row['level'];
$stack[$index]['code']=$row['code'];
$stack[$index]['active']=$row['active'];
}
}
hope this helps



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum