dongpou7275 2012-03-28 05:34
浏览 47

显示默认图像

I have a default image set in the db in the column default_image. If the default_image = 1 I want it to display the default image and if default_image = 0 I want text to say no image available. How do I make sure only the default image is displayed. Here is what I am doing now and it just displays any image that has the same link_id.

the column media_link is the address to the image.

<?php if (!empty($row['default_image'])){
echo "<a href='http://localhost/images".$row['media_link']."'><img src='http://localhost/images".$row['media_link']."'/></a>"; 
}
else{
    echo "<div align=\"center\">No image available</div>";
}?>

What do I do to make default_image "1" in the database display and nothing else? Thanks.

EDIT:
Here is another piece of code to show all the images for that link_id

if ($row['media_link']){
echo "<a href='http://localhost/t_images".$row['media_link']."'><img src='http://localhost/images".$row['media_link']."' /></a>"; 
}
else{
    echo "<div align=\"center\">No images available</div>";
}
}

there is 6 images for this current id
When i echo the vardump on this page the correct image has this
string(1) "1"
while the other 5 images "non default"
show this string(1) "0"
I am not sure how to show only the correct default image where it goes on the page in my first code. Does this info help at all?

EDIT AGAIN/FIXED:
I fixed it by adding ORDER BY default_image DESC to the end of my query. Don't know if that is the best thing to do but if anyone has any other suggestions i would be glad to hear them. Thanks everyone for all your help. You all gave great answers but in the end I just added the order by statement to my query and it works that way so I am happy. Thanks!

  • 写回答

3条回答 默认 最新

  • dtpt75860 2012-03-28 05:40
    关注

    Check Default_image against 1 instead of empty.
    try: ..

    <?php
    if( isset($row['default_image']) && $row['default_image'] == 1){
    echo "<a href='http://localhost/images".$row['media_link']."'><img src='http://localhost/images".$row['media_link']."'/></a>"; 
    }else{
        echo "<div align=\"center\">No image available</div>";
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错