I need some help I am a bit stuck:
I would like it so that IF a row in a table equals YES then it displays a certain image, however IF that row in the table equals NO then it displays another image.
Do you have any ideas?
if($fetch["g1"] == 1) $buffer .= 'Group 1, ';
if($fetch["g2"] == 1) $buffer .= 'Group 2, ';
if($fetch["g3"] == 1) $buffer .= 'Group 3, ';
echo substr($buffer,0,-2).' ';
Your question is pretty vague, but this shows how to fetch a row and conditionally choose the source for an <img>
tag:
# fetch the row
$row = mysql_fetch_array(mysql_query("SELECT * FROM table WHERE foo=$bar"));
# determine image to show
$img = $row['field'] == 'YES' ? 'img-one.gif' : 'img-two.gif';
# output
echo "<img src=\"$img\" />";
So, I'm going to assume you have a table that's similar to the following:
CREATE TABLE `mytable` (
`id` int NOT NULL AUTO_INCREMENT,
`some_data` varchar(128),
`is_enabled` int(1) NOT NULL default 0,
PRIMARY KEY(`id`)
);
Let's say that is_enabled is the row we want to look at. You could perform something similar to the following.
$sql = 'SELECT `is_enabled`';
$sql .= ' FROM `mytable`';
$sql .= ' WHERE `id` = 1234';
$result = mysql_query($sql);
if ($result && mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
if ($row['is_enabled']) {
// This row is enabled.
} else {
// This row is disabled.
}
//Alternatively, do something like this:
?>
<img src="<?php echo $row['is_enabled'] ? '/row_is_yes.gif' : '/row_is_no.gif'; ?>" />
<?php
}
}
Without more information, however, this is the most help I can give.