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 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀