if else display image based on MySQL field
Posted: Wed Jun 13, 2007 3:46 pm
Hello,
I am displaying the results of a my SQL table in HTML via PHP, and what I want to do for the first <td> to display an image based upon data in one of the MySQL columns. The Column in MySQL is named 'f15' and I want to display the image if the data in the column is equal to 1.
Here is what I have right now:
Again, I want to display the image if column f15 in the MySQL table is =1 and I want it to display with the HTML <td> syntax.
I am displaying the results of a my SQL table in HTML via PHP, and what I want to do for the first <td> to display an image based upon data in one of the MySQL columns. The Column in MySQL is named 'f15' and I want to display the image if the data in the column is equal to 1.
Here is what I have right now:
Code: Select all
<?php
$connection = mysql_connect("localhost","username","password");
mysql_select_db ('DBName');
$sql = "SELECT f2,f3,phone,f8,f9,f10,f11,f12,f13,f15 FROM station ORDER BY f11 ASC" ;
$sql_resulta = mysql_query($sql,$connection) or die('Query failed: ' . mysql_error());
$img = '';
//result set
$rs = mysql_query($sql);
//creating the table w/ headers
echo "<table id='display' align='center'><tr><td id='header'>Airport Indicator</td><td id='header'>State</td><td id='header'>Airport Code</td><td id='header'>Airport Name</td><td id='header'><a href='#' onClick='FuncShowHide()'> More Info.</a></td><td id='header'>Select this Location</td></tr>";
if($myinfo[f15] == 1) {
$img = '<td><img src="icons/apo.gif" width="15" height="17" alt="airportindicator"></td>';
}
echo $img;
//row for each record
while ($row = mysql_fetch_array($rs)) {
echo"<tr id='trX'><td>" . $row['f11'] . "</td><td>" . $row['f2'] . "</td><td>" .$row['f3'] ."</td></tr>";
echo"<tr id='hideShow' style='display:none'><td>" . $row['f8'] . "</td><td>" . $row['f9'] . "</td><td>" . $row['f10'] . "</td><td>" .$row['f11'] ."</td><td>" .$row['f12'] ."</td><td>" .$row['phone'] ."</td></tr>";
}
echo "</table>";
//close the db
mysql_close();
echo "</body>";
echo "</html>";
?>