[英]Output 2 Column / 2 Row Table - PHP / MySQL - For Loop
Right now, I am attempting to have a For
loop create a table displaying the different Herds (Groups) in the Database. 现在,我正在尝试让
For
循环创建一个表,以显示数据库中不同的牧群(组)。
As of now, my code looks like this: 截至目前,我的代码如下所示:
echo '<table>';
for($i = 0; $i < $numrows; $i++) {
$row = mysql_fetch_array($result)
$name = $row['name'];
$avatar = $row['avatar'];
$link = $row['link'];
echo '<tr>';
echo '<td>'.$avatar.'</td>';
echo '<td><a href="'.$link.'">'.$name.'</a></td>';
echo '</tr>';
}
echo '</table>';
Which, displays this: 显示以下内容:
[Avatar] [Name]
[头像] [名称]
[Avatar] [Name][头像] [名称]
[Avatar] [Name][头像] [名称]
How would I be able to produce this (all being separate records): 我将如何产生这个(所有都是单独的记录):
[Avatar] [Name] [Avatar] [Name]
[头像] [名称] [头像] [名称]
[Avatar] [Name] [Avatar] [Name][头像] [名称] [头像] [名称]
[Avatar] [Name] [Avatar] [Name][头像] [名称] [头像] [名称]
Any help would be much appreciated. 任何帮助将非常感激。 Also, If I am missing something, please let me know.
另外,如果我缺少什么,请告诉我。
Try this. 尝试这个。
<?php
echo '<table>';
echo '<tr>';
$numrows = 10;
$col = 2;
for($i = 0; $i < $numrows; $i++) {
$name = "name";
$avatar = "avatar";
$link = "localhost";
if($i % $col == 0){
echo '</tr><tr>';
}
echo '<td>'.$avatar.'</td>';
echo '<td><a href="'.$link.'">'.$name.'</a></td>';
}
echo '</tr>';
echo '</table>';
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.