gpt4 book ai didi

php - 打印包含 php 和 sql 值的表

转载 作者:行者123 更新时间:2023-11-29 09:02:42 25 4
gpt4 key购买 nike

我需要打印几行,并在每行中打印几个 td... 3 td 后,它应该添加一个 tr 但我不知道如何解决这个问题。

echo '<table>';
for($counter=0; $counter <= $row2 = mysql_num_rows($result2);counter++) {
print("<tr>");

while($row2 = mysql_fetch_array( $result2 )) {
$_name = $row2["_name"];
$_image = $row2["_image"];

print("<td valign='top' width='230px' height='148px'>");
print("<p class='p_imageStyle'>$_name</p>");
print("<img class='custom' alt='' src='$_image' />");
print("</td>");
}

print("</tr>");
}

echo '</table> ';

最佳答案

  echo '<table>';
$counter=1;
while($row2 = mysql_fetch_array( $result2 )) {
if($counter%3==1)
print("<tr>");
$_name = $row2["_name"];
$_image = $row2["_image"];

print("<td valign='top' width='230px' height='148px'>");
print("<p class='p_imageStyle'>$_name</p>");
print("<img class='custom' alt='' src='$_image' />");
print("</td>");
if($counter%3==0)
print("</tr>");
$counter++;
}
$counter--;
$rem=3-$counter%3; //modifed as per alartur
for($i=0;$i<$rem;$i++)
{
echo "<td></td> //print remaining td
}
if($rem!=0)
echo "</tr>"; //close tr if not closed
echo '</table> ';

关于php - 打印包含 php 和 sql 值的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8115385/

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