有人可以帮我解决浏览返回记录的问题吗?我有一个mysql查询:
if(isset($_GET['record'])) {
$record_current = $_GET['record'];
}else{
$record_current = 1;
}
$useremail = $_SESSION['useremail'];
$view_sql = "SELECT * FROM missions, calendar, bookings
WHERE missions.missions_id = calendar.missions_id
AND calendar.calendar_id = bookings.calendar_id
AND bookings.booking_email ='$useremail' LIMIT $record_current,1";
$view_result = mysql_query($view_sql) or die(mysql_error());
$view_count = mysql_num_rows($view_result);
$rsView = mysql_fetch_assoc($view_result);
查询产生所需的结果。这些值用于填写动态表单。我遇到的问题是正确浏览记录。我正在使用此代码进行导航(以允许用户查看他们所做的所有预订)。编码:
<span class="label"><?php if($record_current > 1) { ?><a href="view.php?record=<?php echo $record_current - 1; ?>" >Previous</a><?php } ?></span>
<span class="element"><?php if($record_current < $view_result) { ?><a href="view.php?record=<?php echo $record_current + 1; ?>" >Next</a><?php } ?></span>
问题是要显示的第一条记录实际上是查询中的第二条记录,即使显示最后一条记录,也会显示“下一个”链接。如果单击该链接,则会显示一个空白表单。我不知道我做错了什么,我已经玩了几个小时,任何帮助将不胜感激。干杯
编辑
我已经修改了代码(感谢肖恩):
$view_sql = "SELECT SQL_CALC_FOUND_ROWS * FROM missions, calendar, bookings
WHERE missions.missions_id = calendar.missions_id
AND calendar.calendar_id = bookings.calendar_id
AND bookings.booking_email ='$useremail' LIMIT $record_current,1";
$view_result = mysql_query($view_sql) or die(mysql_error());
$view_count = mysql_query("SELECT FOUND_ROWS() AS cnt");
$rsView = mysql_fetch_assoc($view_result);
$adj_count = (mysql_result($view_count, 0, "cnt") - 1);
显然,“SELECT FOUND_ROWS”返回一个从零开始的集合。现在正在工作。感谢所有做出贡献的人。干杯,土豆