0

我查看了之前关于我的脚本问题的帖子的所有回复。一切都很好,但没有一个建议可以很好地解决我的问题。

我正在尝试显示两 (2) 列而不是我当前的一 (1) 列。

我在这里的例子:http: //freeskateboardsticker.com/news/authors.php

我已经多次重写脚本,但我似乎无法正确显示行和列并且仍然保持分页完好无损。

以下是我的脚本,任何建议将不胜感激。

<?php include_once(realpath("templates/top.php")); ?>
<?php include_once(realpath("templates/$templates/mid1.php")); ?>

<?php
$page = @$_GET["page"];
$start = @$_GET["start"];

if (!is_numeric($page) || $page < 1)
    $page = 1;

if ($page == 1)
    $start = 0;
else
    $start = ($page * $authorsPerPage) - $authorsPerPage;

$aResult = mysql_query("select pk_alId, alEmail, alFName, alLName, alBio, alDateJoined from tbl_AdminLogins order by alFName, alLName limit $start, $authorsPerPage");
$numRows = mysql_num_rows(mysql_query("select pk_alId from tbl_AdminLogins order by alFName, alLName"));

if ($numRows > 0) {
    ?>
    <!-- Start Authors -->
    <div align="center">
        <center>
            <TABLE WIDTH="86%" BORDER="0" CELLSPACING="0" CELLPADDING="0"> 
                <TR> 
                    <TD WIDTH="100%" HEIGHT="20" COLSPAN="2" ALIGN="right" class="BodyText" VALIGN="top"><FONT COLOR="#0B75AF"> <?PHP
    if ($page > 1)
        $nav .= "<a href='authors.php?page=" . ($page - 1) . "'><span class='Link1'><u>&#171; Prev</u></span></a> | ";
    for ($i = 1; $i <= ceil($numRows / $authorsPerPage); $i++)
        if ($i == $page)
            $nav .= "<a href='authors.php?page=$i'><span class='Link4'><b>$i</b></span></a> | ";
        else
            $nav .= "<a href='authors.php?page=$i'><span class='Link1'>$i</span></a> | ";

    if (($start + $authorsPerPage) < $numRows && $numRows > 0)
        $nav .= "<a href='authors.php?page=" . ($page + 1) . "'><span class='Link1'><u>Next &#187;</u></span></a>";

    if (substr(strrev($nav), 0, 2) == " |")
        $nav = substr($nav, 0, strlen($nav) - 2);
    echo $nav . "<br>&nbsp;";
    ?></FONT>
                    </TD> 
                </TR> 
            </TABLE>
    <?php while ($aRow = mysql_fetch_array($aResult)) { ?>
                <div align="center"><center>
                        <TABLE WIDTH="720" CELLSPACING="0" CELLPADDING="0" BORDER="0"> 
                            <TR> 
                                <TD WIDTH="185"> <?php if ($showAuthorImages) { ?><img src="imageview.php?what=getAuthorPic&authorId=<?php echo $aRow["pk_alId"]; ?>">&nbsp;<?php } ?></TD> 
                                <TD WIDTH="5" VALIGN="top"> </TD> 
                                <TD WIDTH="530" VALIGN="MIDDLE"><SPAN CLASS="BodyHeading1"><?PHP echo $aRow["alFName"]; ?></SPAN>
                                    <BR><span class="Text1"><?php echo $aRow["alBio"]; ?></span><br></TD> 
                            </TR> 
                            <TR> 
                                <TD COLSPAN="3">  </TD> 
                            </TR> 
                        </TABLE>
                    </center></div>
    <?php } ?>
            <div align="center">
                <center>
                    <table width="96%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td width="100%" height="20" colspan="2" align="right" valign="top">
                                <SPAN CLASS="Text4"><?php echo $nav . "<br>&nbsp;"; ?></SPAN>
                                <br>&nbsp;
                            </td>
                        </tr>
                    </table>
                </center>
            </div>
            <!-- End Authors -->
            <?php
        } else {
            // No authors found in the database
            ?>
            <!-- StartAuthors -->
            <div align="center">
                <center>
                    <table width="96%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td width="100%" colspan="2" bgcolor="#FFFFFF" height="21">
                                <span class="BodyHeading">
                                    <br>No Authors Found
                                </span>
                                <span class="Text1">
                                    <br><br>
                                    No authors were found in the database. Please use
                                    the link below to return to our home page.
                                    <br><br>
                                </span>
                                <a href="index.php">Return Home</a>
                            </td>
                        </tr>
                    </table>
                </center>
            </div>
            <!-- End Authors -->
            <?php
        }
        ?>
4

2 回答 2

0

将循环移动到表内,每次迭代创建一个新行,而不是一个新表:

<div align="center">
    <center>
        <TABLE WIDTH="720" CELLSPACING="0" CELLPADDING="0" BORDER="0"> 
            <?php while ($aRow = mysql_fetch_array($aResult)) { ?>
                <TR> 
                    <TD WIDTH="185"> <?php if ($showAuthorImages) { ?><img src="imageview.php?what=getAuthorPic&authorId=<?php echo $aRow["pk_alId"]; ?>">&nbsp;<?php } ?></TD> 
                    <TD WIDTH="5" VALIGN="top"> </TD> 
                    <TD WIDTH="530" VALIGN="MIDDLE"><SPAN CLASS="BodyHeading1"><?PHP echo $aRow["alFName"]; ?></SPAN>
                        <BR><span class="Text1"><?php echo $aRow["alBio"]; ?></span><br></TD> 
                </TR> 
                <TR> 
                    <TD COLSPAN="3">  </TD> 
                </TR> 
            <?php } ?>
        </TABLE>
    </center>
</div>
于 2012-10-25T19:00:52.963 回答
0
  1. 不要使用字体标签,它已被弃用
  2. br /> 不是 br>
  3. 如果您正在写作,则将所有其他标签也写为小写
  4. 使用一些 MySQLi 库(PDO 等)
  5. 不要将 center 和 div 与 align center 标签放入 while 循环
  6. 在 while 循环中构建表行,而不是每个作者一个表(表在 while 之前开始,表在 while 循环之后结束,在 while 内只保留 tr/td 生成)
于 2012-10-25T18:43:55.380 回答