Jump to content

Display only when DB is filled?


Skipjackrick

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.