【发布时间】:2012-11-07 06:44:34
【问题描述】:
我想为呈现动态数据的页面添加分页。但是当我单击页面链接(1、2、3 等)时,出现以下错误。我是php新手,请帮忙。
注意:未定义索引:C:\wamp\www\HR\HR_Applicants.php 第 4 行中的 Jobid 注意:未定义索引:第 8 行 C:\wamp\www\HR\HR_Applicants.php 中的 Jobid 警告:mysql_result() 期望参数 1 是资源,布尔值在第 18 行的 C:\wamp\www\HR\HR_Applicants.php 中给出 注意:使用未定义的常量 mysql_error - 在第 28 行的 C:\wamp\www\HR\HR_Applicants.php 中假设为“mysql_error”
出现第 4 行错误之后的所有错误是因为当我单击分页链接(即 1、2、3 等)时 Jobid 失去了它的值。最初,当页面加载时,它会落在正常(未分页的页面)上,并且工作正常。单击分页链接时会出现问题。
下面是分页页面的代码。
<?php
session_start();
print_r( $_GET, true );
print_r($_REQUEST['Jobid']);
require 'scripts/connect.php';
//Get the Person's jobid
$jobid = $_GET['Jobid'];
//the number of rows to show per page
$per_page = 2;
//Count the number of items in the database
$pages_query = mysql_query("SELECT COUNT('Personid') FROM person where jobid=$jobid");
//Round the number of pages to the nearest 10
$pages = ceil(mysql_result($pages_query,0) / $per_page);
//Check if there value of page is set
$page = (isset($_GET['page'])) ?(int)$_GET['page']: 1;
//Start counting from zero
$start = ($page -1)* $per_page;
//Select the data from the datbase, but limit it to the number of item per page
$Personid_query ="SELECT * FROM person where jobid=$jobid LIMIT $start ,$per_page";
$Personid = mysql_query($Personid_query) or die(mysql_error);
$row = mysql_fetch_assoc($Personid);
?>
上面的代码就在顶部,就在 HTML 标记之前。以下代码属于 HTML 标记,因为向用户显示的数据是动态的,并且是从找到“jobid”的数据库中选择的。
<fieldset>
<?php do{?>
<p><a href="Resume.php?Personid=<?php echo $row['Personid'];?>"><?php echo $row['Personid']?></a></p>
<?php echo $row['Title'];?> <?php echo $row['Forename']?> <?php echo $row['Surname']?> <?php echo $row['ApplicationDate'];?>
<?php }while ($row = mysql_fetch_assoc($Personid))?>
<br />
<?php
//Show the pagination links at the bottom of the page
if ($pages >= 1 && $page<= $pages)
{
for($i=1;$i<=$pages;$i++)
{
echo '<a href="?page='.$i.'">'.$i.'</a> ';
}
}
?>
</fieldset>
【问题讨论】:
标签: php mysql session hyperlink dynamic-data