php - Show different image depending on value in variable -
just want make sure i'm going in right direction this. have image want replaced/changed if value of variable either 0/1. here code guy doing server side stuff.
<?php //requires mysql_connect create connection $link_state = 0; //if wish don't have check connection, may idea leave in. if ($mysql_connection['connected'] == true) { $result = mysql_query("select * link"); //the bit looking should first row, , should 1 row $count = mysql_num_rows($result); if ($count <= 0) { //interesting... $mysql_error['error'] = true; $mysql_error['description'] = "error: no rows returned table 'link'"; } else { //we should ok continue if ($count > 1) { $mysql_error['error'] = true; $mysql_error['description'] = "warning: found more 1 row in 'link' table!"; } $row = mysql_fetch_array($result); $link_state = intval($row['state']); } } else { $mysql_error['error'] = true; $mysql_error['description'] = "error: no mysql connection!"; } /* after completion of page, $link_state 1 of 2 things: * 0 = offline * 1 = online throws $mysql_error: 1 warning 2 errors */ ?>
okay, i'm assuming little bit of code have value of either 0 or 1 in $link_state.
so can simple inline script relevant image?
<img src="img/<?=($link_state=="0"?"off.jpg":($link_state=="1"?"on.jpg":))?>" />
any insight great :)
thanks in advance.
try this
<?php $img = ($link_state == "0") ? "off.jpg" : "on.jpg"; ?> <img src="./img/<?php echo $img; ?>" />
also use mysqli_*
since mysql_*
depreciated.
Comments
Post a Comment