其他页面的导航按钮仅显示在初始页面上。有什么我想念的吗?出现正确数量的链接,但它们只是消失了。例如,当我点击除第一个链接之外的任何其他链接时,导航按钮不会显示在其他页面上。
<?php
if(isset($_GET["page"])){
$page = $_GET["page"];
} else {
$page = 1;
};
$start = ($page-1) *10;
$result = mysql_query("SELECT foodname,calories,kind,carbohydrates,fat,protein,measurement,measurementunits FROM foodItems WHERE userid = '".$_SESSION['userid']."' LIMIT $start, 10");
?>
<table>
<tr>
<td>
Food Name
</td>
<td>
Calories
</td>
<td>
Kind
</td>
<td>
Carbs
</td>
<td>
Fats
</td>
<td>
Protein
</td>
<td>
Measurement
</td>
</tr>
<?php
while ($row = mysql_fetch_assoc($result)){
echo "<br><tr><td>".$row['foodname'] ."</td><td>".$row['calories']."</td><td>".$row['kind']."</td><td>".$row['carbohydrates']."</td><td>".$row['fat']."</td><td>".$row['protein']."</td><td>".$row['measurement']."</td><td>".$row['measurementunits']."</td></tr><br>";
}
?>
</table>
<?php
$result = mysql_query("SELECT count(foodid) FROM foodItems WHERE userid = '".$_SESSION['userid']."' LIMIT $start, 10");
$row = mysql_fetch_row($result);
$total_records = $row[0];
$total_pages = ceil($total_records / 10);
?>
<table>
<tr>
<?php
for($i = 1; $i <= $total_pages; $i++){
echo "<td><a href='foodDirectory.php?page=".$i."'>".$i."</a></td>";
}
?>
</tr>
</table>
答案 0 :(得分:1)
这里的问题是您限制了总页数的计算。
您在上次查询时不需要 $result = mysql_query("SELECT count(foodid)
FROM foodItems
WHERE userid = '".$_SESSION['userid']."'");
。它应该是:
import my_config