PHP圖片和分頁

以下是我的程式碼,我想呈現一頁只秀出 10張照片,但我改了好幾次,都是跑出45張,請問要如何修改??



<?php
require_once("dbtools.inc.php");

//指定每頁顯示幾筆記錄
$records_per_page = 10;

//取得要顯示第幾頁的記錄
if (isset($_GET["page"]))
$page = $_GET["page"];
else
$page = 1;

//建立資料連接
$link = create_connection();

//執行 SQL 命令
$sql = "SELECT * FROM product WHERE catalog_id = '動物'";
$result = execute_sql("test", $sql, $link);

//取得欄位數
$total_fields = mysql_num_fields($result);

//取得記錄數
$total_records = mysql_num_rows($result);

//計算總頁數
$total_pages = ceil($total_records / $records_per_page);

//計算本頁第一筆記錄的序號
$started_redcord = $records_per_page * ($page - 1);

//將記錄指標移至本頁第一筆記錄的序號
mysql_data_seek($result, $started_redcord);


echo "<div style='border='0';' align='center'>";

//每頁顯示項目數量
$per = 10;

//指定每列顯示幾張照片
$photo_per_row = 5;


//顯示相片縮圖
$i = 1;
while ($row = mysql_fetch_assoc($result))
{
$photo_id = $row["catalog_id"];
$photo_name = $row["pr_id"];
$file_name = $row["name"];
$img = $row["img"] ;
$id = $row["id"];


if ($i % $photo_per_row == 1)
echo "<div align='center'>";



echo "<li class='span4'><div class='thumbnail'><a href='photoDetail.php?album=$catalog_id>&photo=$id'>
<img src='images/$img' style='border-color:Black;border-width:1px;'>
<br><br>$photo_name</a>";


echo "<p></div></li>";
/*
if ($i % $photo_per_row == 0 || $i == $total_photo)
echo "</div>";

$i++; */
}


/* 分頁程式碼 */


//產生導覽列
echo "<div style='clear:both;></div>";
echo "<p align='center'>";
if ($page > 1)
echo "<a href='index3.php?page=". ($page - 1) . "'>上一頁</a> ";

for ($i = 1; $i <= $total_pages; $i++)
{
if ($i == $page)
echo "$i ";
else
echo "<a href='index3.php?page=$i'>$i</a> ";
}

if ($page < $total_pages)
echo "<a href='index3.php?page=". ($page + 1) . "'>下一頁</a> ";

echo "</p>";
echo "</div>";
echo "</div>" ;
mysql_free_result($result);
mysql_close($link);
?>
Sign In or Register to comment.