gpt4 book ai didi

php - 如何在 MySql 中使用 PHP foreach

转载 作者:太空宇宙 更新时间:2023-11-03 10:45:35 26 4
gpt4 key购买 nike

<分区>

我想遍历 mysql 表中的每个结果,并为每一行生成 html div。数据库表如下所示:

--------------------------------
id | color | width | img
--------------------------------
1 | red | 550 | url
--------------------------------
2 | black | 650 | url
--------------------------------

我知道这是如何工作的,但不确定语法。以下是我的尝试。

<?php
// connect to the database

$rows = // get rows from the db table

foreach ($rows) {
<div style="background-color:$color;width:$width;">
<img src="$img">
</div>
}

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