在PHP中if和else语句

时间:2012-10-15 15:15:43

标签: php mysql

任何人都可以帮我解决这个问题。我试图使它成为当mysql表中的值= 1时显示图像。我已覆盖该位并显示图像。有没有办法包含if或else语句来说明mysql表中的值是否为0然后显示不同的图像?

感谢。

<?php
        $get_social_set = get_social();

        while ($social = mysql_fetch_array($get_social_set)) 

        {


    ?>


<table width="100%" border="0">
  <tr>
    <td width="10">&nbsp;</td>
    <td width="30"><?php echo"
            <img width=30px heigh=24px src=\"assets/img/icons/tick.png\"/>"; } ?></td>

3 个答案:

答案 0 :(得分:2)

if ($social['name_of_field_youre_checking'] == 0) { ... }

答案 1 :(得分:0)

这样的东西应该在php文件中起作用:

<?php

$image = false;
// get results from database
// process results
if ( $results === 1) {
    $image = 'tick.png';
} else {
    $image = 'something.png';
}
?>
<img src="<?php echo $image ?>" />

再见

答案 2 :(得分:0)

将图像文件命名为foreg:tick0.png,tick1.png并使用下面的代码'SHOW'作为您的db fieldname:

 <?php echo"<img width=30px heigh=24px src=\"assets/img/icons/tick".$social['SHOW'].".png\"/>"; } ?>