doujiu7704 2014-10-28 16:30
浏览 41
已采纳

来自SQL数据库的文件路径不循环BG图像

I have an Image uploaded to a folder with the filepath stored in a table along with other info (title, description). I would like this info looping inside a repeated div. Both other variables loop correctly, however the filepath variable needs to be used in a background URL and at the moment only echos the value of the last row. Thank you very much for your help, there has got to be a simple solution! -Sean


<?php
    $result = mysql_query("SELECT * FROM `program`");
    $values = mysql_fetch_array($result);
    $globals['filepath'] = $row['filepath'];
    
    

echo "<div>"; // start a table tag in the HTML

while($row = mysql_fetch_array($result)){   //Creates a loop to loop through results


echo "<div class=wrapper3  >

<h2>" . $row['program_name'] . "</h2>
<p>" . $row['program_description'] . "</p>

</div>
<p>         </br>      </p>";

$globals['bgimage'] = $row['filepath'];

}
echo "</div>";


?>

<style type="text/css">
.wrapper3{

    width:85%;
    margin:0 auto;
    padding:20px;
    height:auto;
    color:#FFF;

    background: url(/SMLC/<?php while ($row = mysql_fetch_array($result)){ echo $globals['bgimage'];} ?>
) no-repeat; 
    background-size:cover;
    color:#000;
    height:250px;
    text-align:center;
    background-color:#fff;
    border-radius:6px;
    border:1px solid #0FF;


}

</style>
<?php mysql_close();?>

</div>
  • 写回答

1条回答 默认 最新

  • dongyin6576 2014-10-28 16:42
    关注

    Remove the background from the .wrapper3 in css, and add it to the element as an inline style.

    <?php
    
    $result = mysql_query("SELECT * FROM `program`");
    echo "<div>"; // start a table tag in the HTML
    while ($row = mysql_fetch_array($result)) {   //Creates a loop to loop through results
        $globals['filepath'] = $row['filepath'];
        echo "<div class='wrapper3' style=\"background: url('/SMLC/".$row["filepath"]."');\">
                <h2>" . $row['program_name'] . "</h2>
                <p>" . $row['program_description'] . "</p>
            </div>
            <p></br></p>";
    }
    echo "</div>";
    ?>
    

    NOTE: Use mysqli functions or PDO instead of mysql functions, since, mysql functions are deprecated.

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

报告相同问题?

悬赏问题

  • ¥15 表达式必须是可修改的左值
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题