好吧,我知道有人问过这个问题,但我觉得我的情况有点不同和独特。我将我的 php 和 html 代码合并在一起,它使表 9 个图像长,而不是 3 x 3。如果有人好心帮助我,这也是一个次要问题,我希望将所有图片格式化为相同的大小让表格看起来更好任何帮助都是值得赞赏的。
这是我的表格文件
<?php
// Get our database connector
require("includes/conn.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<div>
<?php
// Grab the data from our people table
$sql = "select filename from people LIMIT 9";
$result = mysql_query($sql) or die ("Could not access DB: " . mysql_error());
$count = mysql_num_rows(result);
$i = 0;
$per_row = 3;
echo '<table><tr>';
while ($row = mysql_fetch_assoc($result))
{
echo "<td><img src=\"images/" . $row['filename'] . "\" alt=\"\" /><br /></td>";
if(++$i % $per_row == 0 && $i > 0 && $i < $count) {
# Close the row
echo '</tr><tr>';
}
}
for($x = 0; $x < $per_row - $i % $per_row; $x++) {
echo '<td></td>';
}
echo '</tr></table>';
?>
</div>
</body>
最佳答案
你有:
$count = mysql_num_rows(result);
而不是:
$count = mysql_num_rows($result);
这是一个有效的模拟,使用数组而不是 mysql 调用:http://codepad.org/Fyv2mIvS
关于php - 制作 PHP 图像表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12994198/