【问题标题】:Making a PHP table of images [closed]制作图像的 PHP 表 [关闭]
【发布时间】:2012-10-11 05:53:38
【问题描述】:

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

【问题讨论】:

    标签: php html mysql css


    【解决方案1】:

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

    【讨论】:

    • 没有骰子,但感谢您的关注,我会在早上多看一看,然后解决这个问题
    【解决方案2】:

    你有:

    $count = mysql_num_rows(result);
    

    代替:

    $count = mysql_num_rows($result);
    

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

    【讨论】:

    • 感谢您的回复,我很感激我会在上午查看它
    • 放上钱的符号就很有帮助。我需要研究尺寸和结构,但我会弄清楚的。我相信金钱符号是我问题的很大一部分。谢谢
    • 额外的循环用于填充最后一行的剩余单元格。
    • 能够在你们的帮助下顺利进行,我很感激
    猜你喜欢
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-06
    • 1970-01-01
    • 2013-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多