このコードは、データベースから画像を取得するためのものですが、画像の取得には適していますが、4つの画像を1行に表示したい..そして、else条件でエラーが表示されます。誰か助けてください。
$page_title = 'animals';
include('includes/header.php');
?>
<link rel="stylesheet" type="text/css" href="css/secondary.css"/>
<?php
$tbl_name=$db_prefix."images";
$adjacents = 3;
$query = "SELECT COUNT(*) as num FROM $tbl_name";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];
$targetpage =$base_url . 'animal.php';
$limit = 50;
if(!isset($_REQUEST['page']))
{
$page=1;
}
else
{
$page=$_REQUEST['page'];
}
if($page)
$start = ($page - 1) * $limit;
else
$start = 0;
$query="SELECT image_id, image_name, image_desc, image_size, image_title FROM " . $tbl_name . " WHERE image_category IN (1) LIMIT ". $start.",". $limit;
$result=mysql_query($query) or die("Invalid query: " . mysql_error());
if ($page == 0) $page = 1;
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$lpm1 = $lastpage - 1;
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class='pagination'>";
if ($page > 1)
$pagination.= "<a href='$targetpage?page=$prev'>Previous </a>";
else
$pagination.= "<span class='disabled'>Previous </span>";
if ($lastpage < 7 + ($adjacents * 2))
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2))
{
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
}
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a href=\"$targetpage?page=1\">1 </a>";
$pagination.= "<a href=\"$targetpage?page=2\">2 </a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
}
else
{
$pagination.= "<a href=\"$targetpage?page=1\">1 </a>";
$pagination.= "<a href=\"$targetpage?page=2\">2 </a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
}
}
if ($page < $counter - 1)
$pagination.= "<a href=\"$targetpage?page=$next\">Next </a>";
else
$pagination.= "<span class=\"disabled\">Next </span>";
$pagination.= "</div>\n";
}
?>
<?php echo $pagination; ?>
<br /><br /><br /><br /><br /><br />
<p id="categoryheading">Animals</p>
<br />
<div id="searchphoto">
<table >
<?php
$count=0;
do
{
?>
<tr>
<?php
if($count==4)
{?>
</tr>
<tr>
<td style="width: 150; " >
<a href="animal_pg2.php?image_id=<?php echo base64_encode($row['image_id']); ?>"><img src="<?php echo 'thumbnail_images/' . $row['image_name'];?>"/></a>
</td>
<?php
$count++;
}
?>
<?php
else
{
?>
<td style="width: 150; " >
<a href="animal_pg2.php?image_id=<?php echo base64_encode($row['image_id']); ?>"><img src="<?php echo 'thumbnail_images/' . $row['image_name'];?>"/></a>
</td>
<?php
$count++;
?>
<?php
}
?>
<input type="hidden" name="image_id" value="<?php echo $image_id; ?>" >
<?php
}
while($row=mysql_fetch_assoc($result));
?>
</table>
<?php echo $pagination; ?>
</div>
<br /><br /><br /><br /><br /><br /><br />
<?php include('includes/footer.php');?>