gpt4 book ai didi

php - 在多列中显示数据

转载 作者:太空宇宙 更新时间:2023-11-04 15:00:37 25 4
gpt4 key购买 nike

您好,我需要从 mySQL 表中构建一个包含四列的表。这是我现在拥有的:

 <?php

"<table>";
while ( $row = mysql_fetch_array( $result , MYSQL_ASSOC) )
{
"<tr>";
"<td>";
print("<p><img id='g1' src='/$row[img]' width=130 height=130 onClick='f1()'>" );
print( "<p> Name: $row[name] <br>");
"</td>";
"</tr>";
"</table>";
}


?>

输出将是一个像这样的列表:

enter image description here

我需要表格像这样分成四列:

enter image description here

这可能吗,我该怎么做?

最佳答案

只需移动 <tr> s 到 while 之外.

"<table><tr>";
while ($row = ...) {
"<td>";
...
"</td>";
}
"</tr></table>";

我假设这是某种伪代码,因为您实际上并没有将字符串写入任何内容。您也不应该使用 mysql_在新代码中运行,但改用 PDO 或 mysqli。

关于php - 在多列中显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16469284/

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