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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀