我在php中使用html字符串在单个列中显示sql查询结果:
while($row = mysqli_fetch_array($q)){
$id = $row['id'];
$title = $row['title'];
$desc = $row['description'];
$link = $row['link'];
$output .= '<a href="' . $link . '">
<h3>' . $title . '</h3>
<p>' . $desc . '</p>
</a>';
}
答案 0 :(得分:0)
感谢hungrykoala获取有关此问题的帮助
$i = 0 ;
$resultsPerRow = 2 ;
$output = '<tr>';
while($row = mysqli_fetch_array($q)){
$i++;
$id = $row['id'];
$title = $row['title'];
$desc = $row['description'];
$link = $row['link'];
$output .= '<td><a href="' .$link. '">' .$title. '<br>' .$desc. '</a></td>';
if ($i % $resultsPerRow == 0) {
$output .= '</tr><td><br></td><tr>';
}
}
echo($output);
然后输出到表格标签