dsms21398 2014-10-02 05:22
浏览 15
已采纳

用DB image PHP替换静态图像

I have a div of 40 images(nopreview.png), What I am trying to do is to replace the nopreview.png with the images from db, so if I have 10 images in DB, so out of 40 nopreview.png will be replaced with images from DB keeping the 30 nopreview.png as it is.

HTML
<div class="holder">
<img src="nopreview.png"/>
<img src="nopreview.png"/>
</div>

PHP

$uid="XXXXX";
$check = "SELECT rqid FROM users WHERE fbid = $uid LIMIT 0,250";
$rs = mysqli_query($con,$check);
if(mysqli_num_rows($rs)>0): 
while($row = mysqli_fetch_assoc($rs)):
$reqid= $row['rqid'];
$requests = explode(',',$reqid);
foreach(array_unique($requests) as $request_id) {
echo $request_id."<br>";
echo"<img src='https://graph.facebook.com/$request_id/picture?width=78&height=78' />";
echo "<hr>";
}
endwhile;
endif;

Stuck in where to put the images div?

  • 写回答

1条回答 默认 最新

  • duangu9997 2014-10-02 05:34
    关注

    You're trying to work with PHP like Javascript.

    • Javascript is for DOM manipulation.
    • PHP is embedded into HTML, and creates HTML (most of the time).

    Sccrap your HTML file. Your file "images.php" will look sth like:

    <div class="holder">
    <?php
    $uid="XXXXX";
    $check = "SELECT rqid FROM users WHERE fbid = $uid LIMIT 0,250";
    $rs = mysqli_query($con,$check);
    $imagecount=0;
    while($row = mysqli_fetch_assoc($rs)) {
        $reqid= $row['rqid'];
        $requests = explode(',',$reqid);
        foreach(array_unique($requests) as $request_id) {
            echo"<img src='https://graph.facebook.com/$request_id/picture?width=78&height=78' />";
            $imagecount++;
        }
    }
    for(;$imagecount<40;$imagecount++) {
        echo("<img src=\"nopreview.png\" />");
    }
    ?>
    </div>
    

    So you will always have your 40 images, starting with the available ones and filling at the end with nopreview.png if required.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写