如何才能将其显示在第一页上?我如何分离两个细胞?

时间:2011-03-21 07:06:35

标签: php mysql pagination html-table cell

这段代码几乎只显示了一个包含16个单元格(4列4行)的表格。除右上方外,还有两个“保留”单元格。此代码也分页。

我想用这段代码解决两件事。现在两个“保留的细胞”是相同的。这意味着两个单元格都表示保留。如何制作它以便我可以更改两个保留单元格内的内容。对不起,如果这有点难以理解。

另外,我希望两个保留的单元格只显示在第一页上。除了第一页之外,它只会回显一个包含4x4单元格的表格,就像保留的单元格不存在一样。

任何人都可以这样做吗?

不用多说,这是代码:                             

        $Page = $_GET["Page"];
        if(!$_GET["Page"])
        {
            $Page=1;
        }

        $Prev_Page = $Page-1;
        $Next_Page = $Page+1;

        $Page_Start = (($Per_Page*$Page)-$Per_Page);
        if($Num_Rows<=$Per_Page)
        {
            $Num_Pages =1;
        }
        else if(($Num_Rows % $Per_Page)==0)
        {
            $Num_Pages =($Num_Rows/$Per_Page) ;
        }
        else
        {
            $Num_Pages =($Num_Rows/$Per_Page)+1;
            $Num_Pages = (int)$Num_Pages;
        }

        $strSQL .=" order  by GalleryID ASC LIMIT $Page_Start , $Per_Page";
        $objQuery  = mysql_query($strSQL);
$cell = 0;
echo '<table border="1" cellpadding="2" cellspacing="1"><tr>';
while($objResult = mysql_fetch_array($objQuery))
{
  if($cell % 4 == 0) {
    echo '</tr><tr>';
  }

  if($cell == 2 || $cell == 3) {
    echo '<td>RESERVED</td>'; **//How do I make it so there are two separate reserve slots,  
  rather than one <td> which controls both cells?** 
  } else {
    echo '<td><img src="https://s3.amazonaws.com/thumbnails/' . $objResult["Picture"] . '" />' .
            $objResult["GalleryName"] . '</td>'; }
  $cell++;
}
echo '</tr></table>';
    ?>

        <br>
view more:
        <?php
        if($Prev_Page)
        {
            echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'>prev</a> ";
        }
            {
                echo "|";
        }
        if($Page!=$Num_Pages)
        {
            echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>next</a> ";
        }
        ?>


</body>
</html>
<?php
mysql_close($objConnect);
?>

1 个答案:

答案 0 :(得分:0)

if($cell == 2) {
    echo '<td>RESERVED</td>';
} elseif ($cell == 3) {
    echo '<td>The other cell</td>';
} else {
    echo '<td><img src="https://s3.amazonaws.com/thumbnails/' . $objResult["Picture"] . '" />' .
    $objResult["GalleryName"] . '</td>'; }
    $cell++;
}

编辑:要明白你到底发生了什么,这有点令人沮丧,所以我重写了这一点。这几乎就是您的代码应该是什么样子。如果你无法理解这里的基本条件,你需要在自己的时间上投入更多的工作来理解基础知识,因为很多这些东西都很简陋。

$Page = max((int)$_GET["Page"], 1);
$Prev_Page = $Page - 1;
$Next_Page = $Page + 1;

$Page_Start = max(0, ($Per_Page * ($Page - 1) - 2));
if ($Page === 1) $Per_Page = $Per_Page - 2;
$Num_Pages = ceil($Num_Rows / $Per_Page);

$strSQL .= "ORDER BY GalleryID ASC LIMIT {$Page_Start},{$Per_Page}";
$objQuery = mysql_query($strSQL);

$cell = 0;
$total = mysql_num_rows($objQuery);
?>

<table border="1" cellpadding="2" cellspacing="1">
    <? for ($cell = 0; $cell < $total; ++$cell) : ?>
        <? if ($cell % 4 === 0) : ?>
            <tr>
        <? endif; ?>
        <td>
            <? if ($Page === 1 && $cell === 2) : ?>
                First reserved cell
                <? --$cell; ?>
            <? elseif ($Page === 1 && $cell === 3) : ?>
                Second reserved cell
                <? --$cell; ?>
            <? else: ?>
                <? $objResult = mysql_fetch_array($objQuery); ?>
                <img src="https://s3.amazonaws.com/thumbnails/<?=$objResult["Picture"]; ?>" />
                <?=$objResult["GalleryName"]; ?>
            <? endif; ?>
        </td>
        <? if ($cell % 4 === 3) : ?>
            </tr>
        <? endif; ?>
    <? endfor; ?>
</table>

<br>
view more:
<?php
    if($Prev_Page) {
        echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'>prev</a> ";
        if($Page != $Num_Pages) echo " | ";
    }

    if($Page != $Num_Pages) {
        echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>next</a> ";
    }
?>


</body>
</html>
<?php
mysql_close($objConnect);
?>
相关问题