php分页未定义索引

时间:2015-09-11 14:16:03

标签: php pagination

请帮助,我正在尝试创建php分页。我第一次运行它时显示了我指定的行的确切10条记录,但是一旦我点击下一条以获得另外10条它就会返回:

  

注意:未定义的索引:第7行的C:\ wamp \ www \ seore \ 1.em \ r \ recordsbycourse.php中的课程   注意:未定义的索引:第8行的C:\ wamp \ www \ seore \ 1.em \ r \ recordsbycourse.php中的课程   注意:未定义的索引:第9行的C:\ wamp \ www \ seore \ 1.em \ r \ recordsbycourse.php中的课程

以下是代码:

<?php
include_once("mysession.php");
include_once("connect.php");
 ?>

<?php
    $course_code = $_POST['course'];  
    $semester = $_POST['semester'];
    $level = $_POST['level'];
    $result1 = mysqli_query($con, "SELECT * 
                                   FROM  srcoe_nce_courses_registration 
                                   WHERE course_code = '$course_code'        
                                    AND  semester = '$semester'")
    or die(mysqli_error($con));

    $row1=mysqli_fetch_array($result1);     
    $regno= $row1['regno'];
?>

HTML:

<html>
   <head>
      <meta http-equiv="Content-Language" content="en-us">
      <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
      <title>SRCOE</title>
   </head>
   <style>
      body{ font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;}
      a{color:#666;}
      #table{
      margin: 0 auto;
      background: #333;
      box-shadow: 5px 5px 5px #888888;
      border-radius: 6px 0px 31px 17px;
      color: #0C0;
      padding: 1px;
      }
      #table1{margin:0 auto;}
   </style>
   <center>
      <body>
         <table border="1" width="950" cellspacing="1">
            <tr>
               <td width="98%" bordercolorlight="#000080" 
                  bordercolordark="#000080">
                  <table border="1" width="942" cellspacing="0" cellpadding="0" height="10">
                     <tr>
                        <td width="100%" bgcolor="#008000" align="center" height="17" 
                           style="border-style: solid; border-width: 1px" bordercolorlight="#FFFFFF" 
                           bordercolordark="#FFFFFF" nowrap>
                           <font face="Trebuchet MS">
                           <img border="0" src="header1.jpg" width="938" 
                              height="100"></font>
                        </td>
                     </tr>
                  </table>
                  <table border="1" width="100%" cellspacing="0" cellpadding="0" height="32" 
                     id="table1">
                     <tr>
                        <td width="99%" bgcolor="#008000" align="center" height="30" 
                           style="border-style: solid; border-width: 1px" bordercolorlight="#FFFFFF" 
                           bordercolordark="#FFFFFF" nowrap>
                           <?php
                              include_once("academic_menu.php");
                              ?>
                        </td>
                     </tr>
                  </table>
            <tr>
               <td align="center" width="98%" bgcolor="#FFFFFF" height="20">
                  <font size=2 name="Times New Roman" color="Black" border="0" >
                     <table border="1" cellpadding="5" id="table" bordercolordark="#008000" 
                        style="border-collapse: collapse" width="100%">
                        <tr>
                           <th bgcolor="#008000" style="border-left-style: solid; border-left-width: 1px; 
                              border-right-style: solid; border-right-width: 1px; border-top-style: solid; 
                              border-top-width: 1px" >
                              <font size=2 name="Times New Roman" color="Black" border="0" >
                              <span style="text-transform: capitalize; text-decoration: none">
                              <font face="Trebuchet MS" color="#000080">Students Records by 
                              Course</font></span></font>
                           </th>
                        </tr>
                     </table>
                     <table border="1" cellspacing="0" cellpadding="0" id="table" 
                        bordercolorlight="#FFFFFF" bordercolordark="#008000" style="border-collapse: 
                        collapse" width="100%">
                        <tr>
                           <td bgcolor="#FFFFFF" align="left" style="border-style: solid; border-width: 
                              1px; ; padding-left:4px; padding-right:4px; padding-top:1px; padding-bottom:1px" 
                              bordercolorlight="#00FF00" bordercolordark="#008000" bordercolor="#008000">
                              <font size=2 name="Times New Roman" color="Black" border="0" >
                                 <center>
                                    <form enctype="multipart/form-data" action="marksby_course.php" name="form" 
                                       method="post">
                                       <table width="100%">
                                          <tr>
                                             <td width="167" height="24" align="right" 
                                                style="border:1px solid #000000; border-
                                                left-style: solid; padding-left:4px; padding-right:4px; padding-top:1px; 
                                                padding-bottom:1px" bordercolorlight="#000000" 
                                                bordercolordark="#000000" bgcolor="#FFFFFF">
                                                <p style="margin-top: 0; margin-bottom: 0">
                                                   <font face="calibri">
                                                   <b style="font-family: Trebuchet MS; font-size: 
                                                      12pt; font-style: normal; font-variant: normal; letter-spacing: normal; line-
                                                      height: normal; orphans: auto; text-align: -webkit-center; text-indent: 0px; 
                                                      text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -
                                                      webkit-text-stroke-width: 0px">
                                                   Course Code:</b></font>
                                             </td>
                                             <td width="739" height="24" align="right" 
                                                style="border:1px solid #000000; border-
                                                left-style: solid; padding-left:4px; padding-right:4px; padding-top:1px; 
                                                padding-bottom:1px" bordercolorlight="#000000" 
                                                bordercolordark="#000000" bgcolor="#FFFFFF">
                                                <p align="left"><font face="Trebuchet 
                                                   MS"><b><span style="font-size: 12pt"><?php echo $row1['course_code']; ?>
                                                   </span></b></font><font size=2 name="Times New Roman" color="Black" border="0" >
                                                   <input type="hidden" id="dep2" name="course_code" 
                                                      size="5" value="<?php echo $row1["course_code"]; ?>">
                                                   </font>
                                             </td>
                                          </tr>
                                          <tr>
                                             <td width="167" height="24" align="right" 
                                                style="border:1px solid #000000; border-
                                                left-style: solid; padding-left:4px; padding-right:4px; padding-top:1px; 
                                                padding-bottom:1px" bordercolorlight="#000000" 
                                                bordercolordark="#000000" bgcolor="#FFFFFF">
                                                <p style="margin-top: 0; margin-bottom: 0">
                                                   <font face="calibri">
                                                   <b style="font-family: Trebuchet MS; font-size: 
                                                      12pt; font-style: normal; font-variant: normal; letter-spacing: normal; line-
                                                      height: normal; orphans: auto; text-align: -webkit-center; text-indent: 0px; 
                                                      text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -
                                                      webkit-text-stroke-width: 0px">
                                                   Course Title:</b></font>
                                             </td>
                                             <td width="739" height="24" align="right" 
                                                style="border:1px solid #000000; border-
                                                left-style: solid; padding-left:4px; padding-right:4px; padding-top:1px; 
                                                padding-bottom:1px" bordercolorlight="#000000" 
                                                bordercolordark="#000000" bgcolor="#FFFFFF">
                                                <p align="left"><font face="Trebuchet 
                                                   MS"><b><span style="font-size: 12pt"><?php echo $row1['course_title']; ?></span></b></font><font size=2 name="Times New Roman" color="Black" border="0" > 
                                                   </font>
                                             </td>
                                          </tr>
                                          <tr>
                                             <td width="167" height="24" align="right" 
                                                style="border:1px solid #000000; border-
                                                left-style: solid; padding-left:4px; padding-right:4px; padding-top:1px; 
                                                padding-bottom:1px" bordercolorlight="#000000" 
                                                bordercolordark="#000000" bgcolor="#FFFFFF">
                                                <font face="calibri" size="2" name="Times New 
                                                   Roman" color="Black" border="0">
                                                <b style="font-family: Trebuchet MS; font-size: 
                                                   12pt; font-style: normal; font-variant: normal; letter-spacing: normal; line-
                                                   height: normal; orphans: auto; text-align: -webkit-center; text-indent: 0px; 
                                                   text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -
                                                   webkit-text-stroke-width: 0px">
                                                &nbsp;Semester: </b></font>
                                             </td>
                                             <td width="739" height="24" align="right" 
                                                style="border:1px solid #000000; border-
                                                left-style: solid; padding-left:4px; padding-right:4px; padding-top:1px; 
                                                padding-bottom:1px" bordercolorlight="#000000" 
                                                bordercolordark="#000000" bgcolor="#FFFFFF">
                                                <p align="left"><font face="Trebuchet MS"><b>
                                                   <span style="font-size: 12pt"><?php 
                                                      if ($row1['semester'] ==1 ){
                                                        echo "First";

                                                      }

                                                      if ($row1['semester'] ==2) {
                                                        echo "Second";

                                                      }



                                                      ?></span></b></font>
                                             </td>
                                          </tr>
                                          <tr>
                                             <td width="167" height="24" align="right" 
                                                style="border:1px solid #000000; border-
                                                left-style: solid; padding-left:4px; padding-right:4px; padding-top:1px; 
                                                padding-bottom:1px" bordercolorlight="#000000" 
                                                bordercolordark="#000000" bgcolor="#FFFFFF">
                                                <span style="font-size: 12pt; letter-spacing: 
                                                   normal"><b>
                                                <span style="font-family: Trebuchet 
                                                   MS">Session</span></b></span><font face="calibri" size="2" name="Times New Roman" 
                                                   color="Black" border="0"><b style="font-family: Trebuchet MS; font-size: 12pt; 
                                                   font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 
                                                   normal; orphans: auto; text-align: -webkit-center; text-indent: 0px; text-
                                                   transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-
                                                   text-stroke-width: 0px">:</b></font>
                                             </td>
                                             <td width="739" height="24" align="right" 
                                                style="border:1px solid #000000; border-
                                                left-style: solid; padding-left:4px; padding-right:4px; padding-top:1px; 
                                                padding-bottom:1px" bordercolorlight="#000000" 
                                                bordercolordark="#000000" bgcolor="#FFFFFF">
                                                <p align="left">
                                                   <font face="calibri" size="2" name="Times New 
                                                      Roman" color="Black" border="0">
                                                   <span style="font-family: Trebuchet MS; font-
                                                      size: 12pt; font-variant: normal; letter-spacing: normal; line-height: normal; 
                                                      orphans: auto; text-align: -webkit-center; text-indent: 0px; text-transform: 
                                                      none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-
                                                      width: 0px; font-weight:700">
                                                   2013/2014</span></font>
                                             </td>
                                          </tr>
                                       </table>
                                       <table border="1" cellspacing="0" cellpadding="0" id="table" 
                                          bordercolorlight="#FFFFFF" bordercolordark="#008000" style="border-collapse: 
                                          collapse" width="100%">
                                       </table>
                                       <table width="100%" style="border-bottom-width: 0px">
                                          <tr>
                                             <td height="21" width="39" bordercolorlight="#000000" 
                                                bordercolordark="#000000" style="border:1px solid #000000; padding-left:4px; 
                                                padding-right:4px; padding-top:1px; padding-bottom:1px" align="center" 
                                                bordercolor="#C0C0C0" bgcolor="#008000" nowrap><b>
                                                <span style="font-size: 11pt">S/No.</span></b>
                                             </td>
                                             <td width="236" height="21" align="left" 
                                                bordercolorlight="#000000" 
                                                bordercolordark="#000000" style="border:1px solid #000000; padding-left:4px; 
                                                padding-right:4px; padding-top:1px; padding-bottom:1px" bgcolor="#008000" nowrap>
                                                <b style="font-size: 11pt; font-style: normal; font-variant: normal; letter-
                                                   spacing: normal; line-height: normal; orphans: auto; text-align: -webkit-center; 
                                                   text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-
                                                   spacing: 0px; -webkit-text-stroke-width: 0px">
                                                <font color="#000000" name="Times New Roman" border="0">
                                                Registration No.</font></b>
                                             </td>
                                             <td width="529" height="21" align="left" 
                                                bordercolorlight="#000000" 
                                                bordercolordark="#000000" style="border:1px solid #000000; padding-left:4px; 
                                                padding-right:4px; padding-top:1px; padding-bottom:1px" bgcolor="#008000" nowrap>
                                                <span style="font-size: 11pt"><b>Student's Full 
                                                Name</b></span>
                                             </td>
                                             <td width="60" height="21" align="center" 
                                                bordercolorlight="#000000" 
                                                bordercolordark="#000000" style="border:1px solid #000000; padding-left:4px; 
                                                padding-right:4px; padding-top:1px; padding-bottom:1px" bgcolor="#008000" nowrap>
                                                <span style="font-size: 11pt"><b>Level</b></span>
                                             </td>
                                          </tr>
                                          <?PHP
                                             //check if the starting row variable was passed in the URL or not
                                             if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) {
                                               //we give the value of the starting row to 0 because nothing was found in URL
                                               $startrow = 0;
                                             //otherwise we take the value from the URL
                                             } else {
                                               $startrow = (int)$_GET['startrow'];
                                             }
                                             ?>
                                          <?php
                                             $query = "SELECT * from  srcoe_nce_courses_registration
                                             where 
                                             srcoe_nce_courses_registration.course_code='$course_code'
                                             and 
                                             srcoe_nce_courses_registration.semester='$semester'
                                             and 
                                             srcoe_nce_courses_registration.level='$level'
                                             order by regno, level asc LIMIT $startrow, 10";

                                             $result = mysqli_query($con, $query) or die(mysqli_error($con));
                                             $sri=0;

                                             // Print out the contents of each row into a table 
                                             while($row =mysqli_fetch_assoc($result)){

                                             //}






                                                 $sri+=1;
                                                 ?>
                                          <tr>
                                             <td width="39" bordercolorlight="#000000" bordercolordark="#000000" 
                                                style="border:1px solid #000000; border-
                                                style: solid; padding-left:4px; padding-right:4px; padding-top:1px; padding-
                                                bottom:1px" align="center" bordercolor="#C0C0C0" bgcolor="#C0C0C0" nowrap>
                                                <span style="font-size: 11pt"><?php echo $sri ; ?>.</span>
                                             </td>
                                             <td width="236" align="left" bordercolorlight="#000000" 
                                                bordercolordark="#000000" 
                                                style="border:1px solid #000000; padding-left:4px; padding-right:4px; padding-
                                                top:1px; padding-bottom:1px" nowrap>
                                                <font size=2 name="Times New Roman" border="0" color="#000000" >
                                                <span style="margin-top: 0; margin-bottom: 0">
                                                <b style="font-size: 10pt; font-style: normal; font-variant: normal; 
                                                   letter-spacing: normal; line-height: normal; orphans: auto; text-align: -webkit-
                                                   center; text-indent: 0px; text-transform: none; white-space: normal; widows: 
                                                   auto; word-spacing: 0px; -webkit-text-stroke-width: 0px"><?php echo $row
                                                   ['regno']; ?></b></span></font>
                                             </td>
                                             <td width="529" align="left" bordercolorlight="#000000" 
                                                bordercolordark="#000000" 
                                                style="border:1px solid #000000; padding-left:4px; padding-right:4px; padding-
                                                top:1px; padding-bottom:1px" bgcolor="#C0C0C0" nowrap>
                                                <p>
                                                   <span style="font-size: 11pt">
                                                   <?php echo $row['fullname']; ?></span>
                                             </td>
                                             <td width="60" bordercolorlight="#000000" bordercolordark="#000000" 
                                                style="border:1px solid #000000; border-
                                                style: solid; padding-left:4px; padding-right:4px; padding-top:1px; padding-
                                                bottom:1px" align="center" bgcolor="#FFFFFF" nowrap>
                                                <?php echo $row['level']; ?>
                                             </td>
                                          </tr>
                                          <?php
                                             }//end whil loop
                                              ?>
                                       </table>
                                 </center>
                              </font>
                           </td>
                        </tr>
                        <tr>
                        <td bgcolor="#008000" align="left" bordercolor="#008000" style="border-style: 
                           solid; border-width: 1px; ; padding-left:4px; padding-right:4px; padding-top:1px; 
                           padding-bottom:1px">
                        <p align="center">
                        <font size=2 name="Times New Roman" color="Black" border="0" face="Trebuchet MS" 
                           >
                        <b><font color="#FFFFFF">Copyright </font><font color="#FF0000">(c)
                        </font><font color="#FFFFFF"> 
                        2014 Sa'adatu Rimi College of Education, Kumbotso-Kano. All Rights 
                        Reserved.</font></b></font></td></form>
                        </tr>
                     </table>
                  </font>
               </td>
            </tr>
         </table>
         <font face="Trebuchet MS">
         </td>
         </tr>
         </table>
         </font>
         </font>
         <table>
            <tr>
               <td><?PHP
                  $prev = $startrow - 10;

                  //only print a "Previous" link if a "Next" was clicked
                  if ($prev >= 0)
                      echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.$prev.'">Previous</a>';
                  ?></td>
               <td>   <?PHP
                  //now this is the link..
                  echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+10).'">Next</a>';
                  ?></td>
            </tr>
         </table>
      </body>
   </center>
   </html

2 个答案:

答案 0 :(得分:0)

这是使用GET的示例。按照完整的代码并按照其中的注释

<?php
    /*
        Place code to connect to your DB here.
    */
    //include_once('admin/config/config.inc.php');  // include your code to connect to DB.
    $tbl_name=$mytablename;     //your table name
    // How many adjacent pages should be shown on each side?
    $adjacents = 3;

    /* 
       First get total number of rows in data table. 
       If you have a WHERE clause in your query, make sure you mirror it here.
    */



     $query = "SELECT COUNT(*) as num FROM $tbl_name  where (registration_no not in (SELECT registration_no FROM student_fees_detail where session='".$_SESSION['session']."' and fees_term='".$_POST['fees_term']."') and class='".$_POST['class']."' )";
         if($_POST['stream']!="")
                        {
                             $query.=" and stream='".$_POST['stream']."'";

                            }
                            if($_POST['name']!="")
                            {
                                 $query.=" and name like '%".$_POST['name']."%'";
                                }
                                 $query.="and session='".$_SESSION['session']."'";

    $total_pages = mysql_fetch_array(mysql_query($query));
    $total_pages = $total_pages[num];

    /* Setup vars for query. */
    $targetpage = $_SERVER['PHP_SELF'];     //your file name  (the name of this file)
    $limit =5;                              //how many items to show per page
    $page = $_GET['page'];
    if($page) 
        $start = ($page - 1) * $limit;          //first item to display on this page
    else
        $start = 0;

        $page_no=$start;                                //if no page var is given, set start to 0

    /* Get data. */

      $sql10 = "SELECT * FROM $tbl_name where (registration_no not in (SELECT registration_no FROM student_fees_detail where session='".$_SESSION['session']."' and fees_term='".$_POST['fees_term']."') and class='".$_POST['class']."' )";
     if($_POST['stream']!="")
                        {
                            $sql10.=" and stream='".$_POST['stream']."'";

                            }
                            if($_POST['name']!="")
                            {
                                $sql10.=" and name like '%".$_POST['name']."%'";
                                }
                             $sql10.="and session='".$_SESSION['session']."' LIMIT $start, $limit";
    $student_info11 = mysql_query($sql10);
    //$row_value=mysql_fetch_array($result);
    //print_r($row_value);

    /* Setup page vars for display. */
    if ($page == 0) $page = 1;                  //if no page var is given, default to 1.
    $prev = $page - 1;                          //previous page is page - 1
    $next = $page + 1;                          //next page is page + 1
    $lastpage = ceil($total_pages/$limit);      //lastpage is = total pages / items per page, rounded up.
    $lpm1 = $lastpage - 1;                      //last page minus 1

    /* 
        Now we apply our rules and draw the pagination object. 
        We're actually saving the code to a variable in case we want to draw it more than once.
    */
    $pagination = "";
    if($lastpage > 1)
    {   
        $pagination .= "<div class=\"pagination\">";
        //previous button
        if ($page > 1) 
            $pagination.= "<a href=\"$targetpage?page=$prev\">&laquo; previous&nbsp; </a>";
        else
            $pagination.= "<span class=\"disabled\">&laquo;previous&nbsp; </span>"; 

        //pages 
        if ($lastpage < 7 + ($adjacents * 2))   //not enough pages to bother breaking it up
        {   
            for ($counter = 1; $counter <= $lastpage; $counter++)
            {
                if ($counter == $page)
                    $pagination.= "<span class=\"current\">&nbsp; $counter&nbsp; </span>";
                else
                    $pagination.= "<a href=\"$targetpage?page=$counter\">&nbsp; $counter&nbsp; </a>";                   
            }
        }
        elseif($lastpage > 5 + ($adjacents * 2))    //enough pages to hide some
        {
            //close to beginning; only hide later pages
            if($page < 1 + ($adjacents * 2))        
            {
                for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
                {
                    if ($counter == $page)
                        $pagination.= "<span class=\"current\">&nbsp; $counter&nbsp; </span>";
                    else
                        $pagination.= "<a href=\"$targetpage?page=$counter\">&nbsp; $counter&nbsp;  </a>";                  
                }
                $pagination.= "...";
                $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
                $pagination.= "<a href=\"$targetpage?page=$lastpage\">&nbsp; $lastpage&nbsp; </a>";     
            }
            //in middle; hide some front and some back
            elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
            {
                $pagination.= "<a href=\"$targetpage?page=1\">&nbsp; 1&nbsp; </a>";
                $pagination.= "<a href=\"$targetpage?page=2\">&nbsp; 2&nbsp; </a>";
                $pagination.= "...";
                for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
                {
                    if ($counter == $page)
                        $pagination.= "<span class=\"current\">&nbsp; $counter&nbsp; </span>";
                    else
                        $pagination.= "<a href=\"$targetpage?page=$counter\">&nbsp; $counter&nbsp; </a>";                   
                }
                $pagination.= "...";
                $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
                $pagination.= "<a href=\"$targetpage?page=$lastpage\">&nbsp; $lastpage&nbsp; </a>";     
            }
            //close to end; only hide early pages
            else
            {
                $pagination.= "<a href=\"$targetpage?page=1\">&nbsp; 1&nbsp; </a>";
                $pagination.= "<a href=\"$targetpage?page=2\">&nbsp; 2&nbsp; </a>";
                $pagination.= "...";
                for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
                {
                    if ($counter == $page)
                        $pagination.= "<span class=\"current\">&nbsp; $counter &nbsp; </span>";
                    else
                        $pagination.= "<a href=\"$targetpage?page=$counter\">&nbsp; $counter &nbsp; </a>";                  
                }
            }
        }

        //next button
        if ($page < $counter - 1) 
            $pagination.= "<a href=\"$targetpage?page=$next\">&nbsp; next &raquo;</a>";
        else
            $pagination.= "<span class=\"disabled\"> &nbsp; next &raquo;</span>";
        $pagination.= "</div>\n";       
    }
?>

答案 1 :(得分:-1)

您应该使用POST方法而不是Service方法。