简体   繁体   English

如何不显示数据库中表的某些部分?

[英]How do I not display certain parts of the table from my database?

http://i.stack.imgur.com/5OTgG.png http://i.stack.imgur.com/5OTgG.png

The image above describes my problem, and provides a visual. 上图描述了我的问题,并提供了视觉效果。 As you can see, I just want to reserve or delete the two spaces on the top-right. 如您所见,我只想保留或删除右上角的两个空格。 How can I achieve this? 我该如何实现?

This is my current code: 这是我当前的代码:

<html>
<head>
</head>
<body>
    <?php
        $objConnect = mysql_connect("localhost","root","") or die(mysql_error());
        $objDB = mysql_select_db("dbname");
        $strSQL = "SELECT * FROM album";
        if (!isset($_GET['Page']))  $_GET['Page']='0';
        $objQuery = mysql_query($strSQL);
        $Num_Rows = mysql_num_rows($objQuery);

        $Per_Page = 12;   // Per Page
        $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 albumID ASC LIMIT $Page_Start , $Per_Page";
        $objQuery  = mysql_query($strSQL);


        echo"<table border=\"0\"  cellspacing=\"1\" cellpadding=\"1\"><tr>";
        $intRows = 0;
        while($objResult = mysql_fetch_array($objQuery))
        {
            echo "<td>"; 
            $intRows++;
    ?>
            <center>
                <img src="https://s3.amazonaws.com/thumbnails/<?=$objResult["Picture"];?>" height="190" width="190" /></a><br>
                <?=$objResult["albumName"];?>
                <br>
            </center>
    <?php
            echo"</td>";
            if(($intRows)%4==0)
            {
                echo"</tr>";
            }
        }
        echo"</tr></table>";
    ?>

        <br>
        <?php
        //DELETED PAGINATION CODE for the sake of simplicity in StackOverflow
                ?>
</body>
</html>
<?php
mysql_close($objConnect);
?>

Your $intRows variable seems to be counting cells, not rows. 您的$ intRows变量似乎在计算单元格,而不是行。 So you can simply identify the top right cells by their numbers, which should be 2 and 3. Add this to your loop: 因此,您可以简单地通过数字来标识右上角的单元格,该单元格应为2和3。将其添加到循环中:

$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>';
  } else {
    echo '<td>'.$objResult["albumName"].'</td>';
  }

  $cell++;
}
echo '</tr></table>';

In your loop, you'd need to put in some conditional statement to break from the default behavior. 在循环中,您需要输入一些条件语句来打破默认行为。

while($objResult = mysql_fetch_array($objQuery))
{
    if(($intRows)%4==0)
    {
        echo"<tr>"; // You forgot this.
    }

    echo "<td>";
    $intRows++;
    if ($intRows == 3 || $intRows == 4) : 
?>
    <!-- special cells -->
<?
    else:
?>
    <center>
        <img src="https://s3.amazonaws.com/thumbnails/<?=$objResult["Picture"];?>" height="190" width="190" /></a><br>
        <?=$objResult["albumName"];?>
        <br>
    </center>
<?php
    endif;

    echo"</td>";
    if(($intRows)%4==0)
    {
        echo"</tr>";
    }
}
// You also need this part:
echo ($intRows %4 > 0 ? "</tr>" : "") . "</table>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM