Skipjackrick Posted February 29, 2008 Share Posted February 29, 2008 So, I have this contest where when a user catches a fish they enter the size of the fish and this small snippet of code is used to display the data of the largest fish caught. Well, the contest is just starting and the page displays blank data. Is there a way to display the result only when the database is filled with an entry? I would like for it to be blank until an entry is made into the DB. It works great otherwise. $query_trout = "SELECT species_id, team_id, MAX(length) FROM submit WHERE species_id=2 GROUP BY team_id"; $result5 = mysql_query($query_trout) or die(mysql_error()); while($row = mysql_fetch_array($result5)) { $team_id = $row['team_id']; $species_id = $row['species_id']; $trout = $row['MAX(length)']; //get team's name from team table get_team_name($team_id); get_species($species_id); } $trout_bonus .=<<<EOD <tr> <td align='center'>$speciesname</td> <td align='center'>$teamname</td> <td align='center'>$trout"</td> </tr> EOD; Link to comment https://forums.phpfreaks.com/topic/93617-display-only-when-db-is-filled/ Share on other sites More sharing options...
pocobueno1388 Posted February 29, 2008 Share Posted February 29, 2008 Try <?php $query_trout = "SELECT species_id, team_id, MAX(length) FROM submit WHERE species_id=2 GROUP BY team_id"; $result5 = mysql_query($query_trout) or die(mysql_error()); if (mysql_num_rows($result5) > 0){ while($row = mysql_fetch_array($result5)) { $team_id = $row['team_id']; $species_id = $row['species_id']; $trout = $row['MAX(length)']; //get team's name from team table get_team_name($team_id); get_species($species_id); } $trout_bonus .=<<<EOD <tr> <td align='center'>$speciesname</td> <td align='center'>$teamname</td> <td align='center'>$trout"</td> </tr> EOD; } else { echo "No fish caught yet."; } Link to comment https://forums.phpfreaks.com/topic/93617-display-only-when-db-is-filled/#findComment-479690 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.