How do I not display certain parts of the table from my database?
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);
?>
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>";
Your $intRows variable seems to be counting cells, not rows. So you can simply identify the top right cells by their numbers, which should be 2 and 3. Add this to your loop:
$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>';
精彩评论