2

好的,我知道有人问过这个问题,但我觉得我的情况有点不同和独特。我将我的 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>

4

2 回答 2

1

我相信你在错误的地方有一个紧密的卷发。您在while检查后立即关闭整个循环以查看是否需要关闭表格行。

于 2012-10-21T02:20:47.397 回答
1

你有:

$count = mysql_num_rows(result);

代替:

$count = mysql_num_rows($result);

这是一个工作模拟,使用数组而不是 mysql 调用:http ://codepad.org/Fyv2mIvS

于 2012-10-21T05:25:15.430 回答