<?
// Set the MySQL Configuration
$db_host = "test";
$db_user = "test";
$db_password = "test";
$db_name = "test";
$db_table = "test";
// Start Connection
$db_connect = mysql_connect ($db_host, $db_user, $db_password);
// Select Database
$db_select = mysql_select_db ($db_name, $db_connect);
$query = "SELECT bird_owner, place_name, funds, place_description FROM bird_locations";
$query2 = "SELECT blue_bird, red_bird, green_bird, gold_bird, black_bird FROM bird_locations";
// this query ($query2) is to select just the birds so can check if any bird = 1 then add a new image cell in table
// Execution MySQL Query
$result = mysql_query($query);
if($result)
{
// table headers
echo '<table width="90%" border="0" align="center" cellspacing="2" cellpadding="10">
<p><p><p>
<tr>
<th align="center"><b>Owner</b></th>
<th align="center"><b>PlaceName</b></th>
<th align="center"><b>Birds</b></th>
<th align="center"><b>Funds</b></th>
<th align="center"><b>Description</b></th>
</tr>
';
//now i add a new row for each result which works.
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo '<tr>
<td align="center"><b>' . $row['bird_owner'].'</b></td>
<td align="center"><b>' . $row['place_name'].'</b></td>
<td align="center"><b><img src="bird_blue_50px.png"/></b></td>
<td align="center"><b>' . $row['funds'].'L$</b></td>
<td align="center"><b>' . $row['place_description'].'</b></div></td>
</tr>';
}
echo '</table>';
}
//Close MySQL connection
mysql_close($db_connect);
?>
When the rows are generated the 3rd cell of a row is an image of a bird, but how can I make it so that if the value of a bird in the database is 1 that it shows an extra cell for another bird image?
e.g. if
- blue_bird value equals 1 show image in row
- red_bird value equals 1 show a red bird image in row also
- green_bird value equals 1 show green bird image
- gold_bird value equals show gold bird image
- black_bird value equals show black bird image
and if there value equals 0 then don’t show that image in table
Split the echo:
Also, mysql_query won’t be supported for long anymore: http://php.net/manual/en/function.mysql-query.php