lilyyan
asked on
how to determain at least one row is returned from a DB table?
Hello,
I want to print a html table only if there is at least one row can be returned from a table.
Foe example, something like:
if ($rowNum >0)
//then print a html table
< table> .....
I guess I need to use mysql_num_rows () to determin the $rowNum. Is this a only choice? or there is a better choice in terms of performance?
Thanks very much for your reply,
lilyyan
I want to print a html table only if there is at least one row can be returned from a table.
Foe example, something like:
if ($rowNum >0)
//then print a html table
< table> .....
I guess I need to use mysql_num_rows () to determin the $rowNum. Is this a only choice? or there is a better choice in terms of performance?
Thanks very much for your reply,
lilyyan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi, thanks so mcuh for your reply. Regards.
<?php-not-quite
$r_Conn = mysql_pconnect(...);
$s_SQL = 'Some query';
$r_Result = mysql_query($s_SQL);
$s_Rows = '';
while(False !== ($a_Row = mysql_fetch_assoc($r_Resul
{
$s_Rows .= 'Add a TR to the list of rows';
}
mysql_free_results($r_Resu
$s_Table = ('' !== $s_Rows) ? 'Table header' + $s_Rows + 'table footer' : '';
echo $s_Table;
?>
sort of thing.
Basically, use a loop to build the output you want into a string.
Outside of the loop, if the string contains anything, then there was data.