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.

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

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路