【问题标题】:Pagination within a dynamic data动态数据中的分页
【发布时间】: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'];?>&nbsp;<?php echo $row['Forename']?>&nbsp;<?php echo $row['Surname']?>&nbsp;&nbsp;&nbsp;&nbsp;<?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


    【解决方案1】:

    您没有在后续页面链接中传递 Jobid 参数。

    echo '<a href="?page='.$i.'">'.$i.'</a> ';
    

    应该是

    echo '<a href="?Jobid='.$_GET['Jobid'].'&page='.$i.'">'.$i.'</a> ';
    

    【讨论】:

    • 谢谢戴尔。有用。我是 php 新手,所以我还在学习很多东西。感谢您的帮助
    • 别担心冠军,很高兴我能帮上忙
    猜你喜欢
    • 1970-01-01
    • 2014-07-21
    • 2012-12-02
    • 1970-01-01
    • 2017-05-30
    • 1970-01-01
    • 1970-01-01
    • 2021-06-04
    • 2013-09-29
    相关资源
    最近更新 更多