gpt4 book ai didi

php - 如何使用 PHP 和我的 sql 在循环中动态设置图像标签内的值

转载 作者:行者123 更新时间:2023-11-29 21:29:55 26 4
gpt4 key购买 nike

我需要帮助。我需要使用 PHP 在 li 元素内动态设置一些数据库值(i.e-image,class)。我在下面解释我的代码。

<ul class="sequence-canvas">
<li class="animate-in">
<div class="intro">
<h2>My Discount Pharmacy //set title from db</h2>
<h3>
We are an end to end healthcare service provider where the doctors can enter their prescriptions, patients can upload their prescriptions. //set subtitle
</h3>
</div>
<img class="iphone" src="img/seq-slider/iphone.png" alt="iPhone4" /> //set image1 from DB
<img class="iphone-shadow" src="img/seq-slider/iphone-shadow.png" alt="" /> //set image2 from DB
</li>
<li>
<img class="ipad" src="img/seq-slider/ipad.png" alt="iPad" />//set image1 from DB
<div class="slide2">
<h2>My Discount Pharmacy // set title from DB</h2>
<p>
We are an end to end healthcare service provider where the doctors can enter their prescriptions, patients can upload their prescriptions. //Set subtitle from DB.
</p>
</div>
<img class="ipad-shadow" src="img/seq-slider/ipad-shadow.png" alt="" /> //set image2 from DB
</li>
</ul>

根据上面的代码,我需要在循环中迭代每组 li 元素并动态设置一些值。我在下面解释我的 php 代码。

<?php 
$sql = mysql_query("select * from phr_news order by news_id desc");

while ($row=mysql_fetch_array($sql)) {
$title = $row['title'];
$subtitle = $row['sub_title'];
$image1 = $row['image1'];
$image2 = $row['image2'];
}
?>

这里我需要迭代循环内的每个 li 元素,并将上述值设置在适当的位置。请帮助我。

最佳答案

我认为这段代码将帮助您获得所需的输出

<?php 
$sql=mysql_query("select * from phr_news order by news_id desc");
while($row=mysql_fetch_array($sql)){ ?><li class="animate-in">
<div class="intro">
<h2>
<?php $row['title']; ?> //set title from db
</h2>
<h3>
<?php $row['sub_title']; ?> //set subtitle
</h3>
</div>
<img class="iphone" src="img/seq-slider/<?php $row['image1']; ?>" alt="iPhone4" /> //set image1 from DB
<img class="iphone-shadow" src="img/seq-slider/<?php $row['image2']; ?>" alt="" /> //set image2 from DB
</li>
<li>
<img class="ipad" src="img/seq-slider/<?php $row['image1']; ?>" alt="iPad" />//set image1 from DB
<div class="slide2">
<h2>
<?php $row['title']; ?> // set title from DB
</h2>
<p>
We are an end to end healthcare service provider where the doctors can enter their prescriptions, patients can upload their prescriptions. //Set subtitle from DB.
</p>
</div>
<img class="ipad-shadow" src="img/seq-slider/<?php $row['image2']; ?>" alt="" /> //set image2 from DB
</li>
<?php } ?>

关于php - 如何使用 PHP 和我的 sql 在循环中动态设置图像标签内的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35340090/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com