0

hello all,,i added a pagination in my table,,before that,all the button is working,but now after i add a pagination,the image button is not now working....is any problem in my codes,this is my comple codes:
hope someone help me out again..

<?php
    if(!isset($_COOKIE['POGI']))
    {
        header("location:index.php");

    }
?>
<?php
include('config2.php');
?>
<?php empty($_GET['id']) ? $_GET['id'] = 1 : null; ?>

<?php 

    if (isset($_POST['Delete'])) {
        if (isset($_POST['del_box'])) {
            $checked = $_POST['del_box'];
            foreach($checked as $msg_id) {
                $del_query = mysql_query("DELETE FROM account_student WHERE id = '$id'");
                $query = mysql_query("UPDATE account_student SET fullname='$fullname, course='$course' WHERE id='{$msg_id}'");
            }
        }
    }

    ?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
body {
    font: normal 11px auto "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
    color: #4f6b72;
    background: #E6EAE9;
}

a {
    color: #c75f3e;
}

#mytable {
    width: 700px;
    padding: 0;
    margin: 0;
}

caption {
    padding: 0 0 5px 0;
    width: 700px;    
    font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
    text-align: right;
}

th {
    font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
    color: #4f6b72;
    border-right: 1px solid #C1DAD7;
    border-bottom: 1px solid #C1DAD7;
    border-top: 1px solid #C1DAD7;
    letter-spacing: 2px;
    text-transform: uppercase;
    text-align: left;
    padding: 6px 6px 6px 12px;
    background: #CAE8EA url(images/bg_header.jpg) no-repeat;
}

td.hide{

    display: none
}

th.nobg {
    border-top: 0;
    border-left: 0;
    border-right: 1px solid #C1DAD7;
    background: none;
}

td {
    border-right: 1px solid #C1DAD7;
    border-bottom: 1px solid #C1DAD7;
    background: #fff;
    padding: 6px 6px 6px 12px;
    color: #4f6b72;
}

th.margin
{
padding:.05px;
}
td.margin
{
padding:.05px;
}

td.alt {
    background: #F5FAFA;
    color: #797268;
}

font.small{
    font-size:13px;
    font-family:"Times New Roman", Times, serif;

th.spec {
    border-left: 1px solid #C1DAD7;
    border-top: 0;
    background: #fff url(images/bullet1.gif) no-repeat;
    font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
}

th.specalt {
    border-left: 1px solid #C1DAD7;
    border-top: 0;
    background: #f5fafa url(images/bullet2.gif) no-repeat;
    font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
    color: #797268;
}
</style>
<title>Student List</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<style type=text/css>
div.pagination {
    alignment-adjust:middle;
    padding: 3px;
    margin: 3px;
}

div.pagination a {
    padding: 2px 5px 2px 5px;
    margin: 2px;
    border: 1px solid #AAAADD;

    text-decoration: none; /* no underline */
    color: #000099;
}
div.pagination a:hover, div.pagination a:active {
    border: 1px solid #000099;

    color: #000;
}
div.pagination span.current {
    padding: 2px 5px 2px 5px;
    margin: 2px;
        border: 1px solid #000099;

        font-weight: bold;
        background-color: #000099;
        color: #FFF;
    }
    div.pagination span.disabled {
        padding: 2px 5px 2px 5px;
        margin: 2px;
        border: 1px solid #EEE;

        color: #DDD;
    }
</style> 
<title>pagination
</title>
</head>
<body>
<div id="container" class="round10">
<?php include_once 'includes/header.php';?>
      <?php include_once 'includes/sidebar.php';?>

      <div id="content" class="left round10">
         <h1><img src="images/images.jpg" width="30" height="30" /> &nbsp; Student List</h1>
         <div class="box box-info">Please click the name of the Students if you want to send them a message</div>
          <div align="right">
          <a href="search.php">
          <u>Search Student?</u>
         </a>
         </div>

<?php
    /*
        Place code to connect to your DB here.
    */
    include('config2.php'); // include your code to connect to DB.

    $tbl_name="account_student";        //your table name
    // How many adjacent pages should be shown on each side?
    $adjacents = 10;

    /* 
       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";
    $total_pages = mysql_fetch_array(mysql_query($query));
    $total_pages = $total_pages[num];

    /* Setup vars for query. */
    $targetpage = "view_student_account.php";   //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;                             //if no page var is given, set start to 0

    /* Get data. */
    $sql = "SELECT fullname, course, year, section, year FROM $tbl_name LIMIT $start, $limit";
    $result = mysql_query($sql);

    /* 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\">« previous</a>";
        else
            $pagination.= "<span class=\"disabled\">« previous</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\">$counter</span>";
                else
                    $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</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\">$counter</span>";
                    else
                        $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";                   
                }
                $pagination.= "...";
                $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
                $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";     
            }
            //in middle; hide some front and some back
            elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
            {
                $pagination.= "<a href=\"$targetpage?page=1\">1</a>";
                $pagination.= "<a href=\"$targetpage?page=2\">2</a>";
                $pagination.= "...";
                for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
                {
                    if ($counter == $page)
                        $pagination.= "<span class=\"current\">$counter</span>";
                    else
                        $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";                   
                }
                $pagination.= "...";
                $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
                $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";     
            }
            //close to end; only hide early pages
            else
            {
                $pagination.= "<a href=\"$targetpage?page=1\">1</a>";
                $pagination.= "<a href=\"$targetpage?page=2\">2</a>";
                $pagination.= "...";
                for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
                {
                    if ($counter == $page)
                        $pagination.= "<span class=\"current\">$counter</span>";
                    else
                        $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";                   
                }
            }
        }

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

    <?php

     echo "<table border='1' cellpadding='10' width='727'>";

        echo "<tr>  <b>
        <th><input type='checkbox' name='del_all' id='del_chkbox' onClick='check_all(document.delForm.chkbox)' /></th>
        <th width='130'><center>Full Name</center></th> <th width='130'><center>Course</center></th> <th class='margin'><center>Section</center></th><th class='margin'><center>Year Enrolled</center></th> <th class='margin'><center>Add Grades</center></th>
        <th class='margin'><center>View Grades</center></th> 
        <th class='margin'><center>Stop</center></th>
        </b>
        </tr>";
        while($row = mysql_fetch_array($result))
        {

            echo "<tr>";
                 echo '<td><input type="checkbox" name="del_box[]" id="chkbox" value="' . $row['id'] . '"/></td>';
                echo '<td><font class="small"><center><a href="write_message.php?id=1">' . $row['fullname'] . '</a></center></font></td>';
                echo '<td><font class="small"><center>' . $row['course'] . '</center></font></td>';
                 echo '<td><font class="small"><center>' . $row['section'] . '</center></font></td>';
                 echo '<td class="margin"><font class="small"><center>' . $row['year'] . '</center></font></td>';
                  echo '<td class="hide"><center>' . $row['username'] . '</center></td>';
                echo '<td><center><a class="btn" href="add_grades.php?id=' . $row['username'] . '&course=' .$row['course'] . '"><span class="icon icon-add">&nbsp;</span></a></center></td>';
                 echo '<td class="margin"><center><a class="btn" href="view_grades.php?id=' . $row['username'] . '&course=' .$row['course'] . '"><span class="icon icon-grades">&nbsp;</span></a></center></td>';


                  echo '<td><center><a class="btn" href="stop.php?id=' . $row['id'] . '"><span class="icon icon-cancel">&nbsp;</span></a></center></td>';
                echo "</tr>"; 

        }


    ?>
    </div>

<?=$pagination?>

  </div>


      <?php include_once 'includes/footer.php';?>
   </div>


</body>
</html>

dasfjdasjfkldf

3
Contributors
14
Replies
16
Views
5 Years
Discussion Span
Last Post by breakzzzz20
0

I am not entirely sure what the problem is from your description unless you are referring to the funny A<< and A>> in your button text which is because you haven't used html entities.

In your code, replace << with &laquo; and >> with &raquo;

0

i'm sorry for my bad explanation,,,,the pagination is working for me,,but the image button
My codes below can't get the id like "stop.php?i....[id]
in the next page of url the id not print,,so that's why my image button can't work,,

 echo '<td><center><a class="btn" href="add_grades.php?id=' . $row['username'] . '&course=' .$row['course'] . '"><spa>n class="icon icon-add"> </span></a></center></td>';
>                  echo '<td class="margin"><center><a class="btn" href="view_grades.php?id=' . $row['username'] . '&course=' .$row['course'] . '"><span class="icon icon-grades"> </span></a></center></td>';
>                   echo '<td><center><a class="btn" href="stop.php?id=' . $row['id'] . '"><span class="icon icon-cancel"> </span></a></center></td>';
>                 echo "</tr>";

and also on the grades button, i only get this url after i clicked the add grades button:

http://localhost/EOG/MY_ADMIN/add_grades.php?id=&course=Computer%20Science 

id should have also a value,i only get the course value..any problem on my codes?

dsfasdjfkljasdflkjlklj1

Edited by breakzzzz20

0

Hi,

This is just a suggestion. Why not remove your pagination script first. Go back to where your script works. Then create a pagination class. If you are not comfortable with writing a class just write it in the simplest form.. like this

  ## filename: pagination.class.php ##

  class PageIt(){

  ## we don't have to define any var here, because this is just a simple class to get you going.

  ## create the pagination function

  function doPagination($total_pages){
  ## since that this is a simple class at the very minimum, we can set our globals below. Otherwise these items must be difine as var above.
  global $tbl_name, $start, $limit;

  ## put your pagination script below,WITHOUT the database query in it. I mean both of them must not be included here. Explanation will be provided below.



  ## this will return the .pagination

  return $pagination;
  }


  }
  ## end of this tiny and simple class

Like what I have already commented inside our little tiny class above, we need to remove and send query to your database here..

   include 'pagination.class.php';
  ## top section of your script here before the while loop.


  ## first do a count query Remember! $tbl_name is global, and has to be define above this section of the script.

   $query = "SELECT COUNT(*) as num FROM $tbl_name";
   $total_pages = mysql_fetch_array(mysql_query($query));
   $total_pages = $total_pages[num];

   ## we instantiate our simple pagination class.
   $page_it = new PageIt;
   $paginate = $page_it->($total_pages);

   ## now our pagination above is ready.. we do the second query for your actual table content. I will be using your own query above. Once again, tbl_name, start, and limit are global here.. these items will get pickup by our pagination class as you click on the pagination items (number).

   /* Get data. */
   $sql = "SELECT fullname, course, year, section, year FROM $tbl_name LIMIT $start, $limit";
   $result = mysql_query($sql);

   ## put the rest of your codes here, and the while loop here the way it was working on your script without the pagination.



   ## Put the pagination where you want it to be showing.
    echo $paginate;

There you have it... S-> L-> mat. :) simple class but strong.. i mean weak ..:)

0

i'm put my while loop in your codes but still not working it has a error:

only my while loop should i put in your codes?

0

Hi,

Please don't call me sir. I just barely turned 19 years old. :) . On the other hand, I always think I am already old, but my parents said not yet. "You are just barely getting in there young man".

Thanks a lot though, I really appreciate it, must be a sign of respect. We don't get that much here in the States. We call each other Dude, or something really geeky in that regards..

Ok, back to your problem, I will do this in two parts.

First, I tried to work on you pagination script, but I think it is missing some features I would like to see in pagination script. I modified some pagination scripts that I stumbled upon on the Internet. I really don't know who was the original author. I think it was 4 to 5 years ago. Overtime, I was experimenting on how to improve this script. However, I think it already maximized its potential that it is now pretty old for me to use in my applications. However, this script has been helpfull to me years back.. It just need 1 variable and 5 globals.

Here we go...copy codes below, save as **pagination.php
**

<?php
function vpagination($numrows){
global $page,$start,$limit,$adjacents,$targetpage;

## edit based on the global assigned above ##
$rowsperpage = $limit; 
$range = $adjacents;


## do not edit beyond this line ----------------------##
$page_v = "";
## calculate total pages
$totalpages = ceil($numrows / $rowsperpage);
## get current page or set a default
if (isset($_GET['page']) && is_numeric($_GET['page'])) {
## page number as integer important
   $page = (int) $_GET['page'];
} else {
## default page number
   $page = 1;
} 
## end if

## current page is greater than total pages...
if ($page > $totalpages) {
## set current page to last page
   $page = $totalpages;
} 
## end if current page 
## if current page is less than first page...
if ($page < 1) {
## set current page to first page
   $page = 1;
} 
## end if
## the offset of the list, based on current page 
$offset = ($page - 1) * $rowsperpage;
##### build the pagination links #####

## if not on page 1, don't show back links
if ($page > 1) {
   ## show << link to go back to page 1
   $page_v .= "<a href='{$targetpage}?page=1'><<</a>";
   ## get previous page num
   $prevpage = $page - 1;
   ## show < link to go back to 1 page
  $page_v .= " <a href='{$targetpage}?page=$prevpage'>Prev</a>  ";

} 
## end if 

## loop to show links to range of pages around current page
for ($x = ($page - $range); $x < (($page + $range) + 1); $x++) {
   ## if it's a valid page number...
   if (($x > 0) && ($x <= $totalpages)) {
   ## if we're on current page...
      if ($x == $page) {
   ## 'highlight' it but don't make a link
         $page_v .= " <span class='current'>$x</span> ";
   ## if not current page...
      } else {
   ## make it a link
         $page_v .= " <a href='{$targetpage}?page=$x'>$x</a> ";
      } ## end else
   } ## end if 
} ## end for each loop

## if not on last page, show forward and last page links        
if ($page != $totalpages) {
   ## get next page
   $nextpage = $page + 1;
   ## echo forward link for next page 
   $page_v .= " <a href='{$targetpage}?page=$nextpage'>Next</a> ";
   ## echo forward link for lastpage
   $page_v .= " <a href='{$targetpage}?page=$totalpages'>>></a> ";
} ## end if
############ end build pagination links ##########
return $page_v;
}


?>

I will be back for the second part later.. , before going any further, let explain how the pagination work as far as the design aspects of it. Looking at the codes I have provided above, you would notice that I only used anchor links, and span tags. The objective is wrap the output of the pagination function with a div tags so that you can control the css style.

0

ok, here is the second part. All you need to do is put back the css styling on your html codes. This should work..

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<!-- put back your css styling here -->

<title>pagination
</title>
</head>
<body>
<div id="container" class="round10">

<?php 
include_once 'includes/header.php'; 
include_once 'includes/sidebar.php';
?>

<div id="content" class="left round10">

<h1><img src="images/images.jpg" width="30" height="30" /> &nbsp; Student List</h1>

<div class="box box-info">Please click the name of the Students if you want to send them a message</div>
<div align="right">
<a href="search.php">
<u>Search Student?</u>
</a>
</div>

<?php
/*
Place code to connect to your DB here.
*/
include('config2.php'); // include your code to connect to DB.
## include pagination script 

include ('pagination.php');

$tbl_name="account_student"; //your table name

## count rows from database for pagination.
$query = "SELECT COUNT(*) as num FROM $tbl_name";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];

## pagination settings
$adjacents = 5;
$limit = 5; //how many items to show per page
$targetpage = "view_student_account.php"; //your file name (the name of this file)


if(isset($_GET['page'])){
    $page = $_GET['page'];
    $start = ($page - 1) * $limit; //first item to display on this page


    }
else{
    $start = 0; //if no page var is given, set start to 0
    $page = 1;
}

## initialize pagination
$pagination = vpagination($total_pages);

$sql = "SELECT id, fullname, course, year, section, year FROM $tbl_name LIMIT $start, $limit";
$result = mysql_query($sql);

## do not put strain on your server by echoing html tags. Just close the php., and then reopen if needed ##
echo "<table border='1' cellpadding='10' width='727'>";
echo "<tr> <b>
<th><input type='checkbox' name='del_all' id='del_chkbox' onClick='check_all(document.delForm.chkbox)' /></th>
<th width='130'><center>Full Name</center></th> <th width='130'><center>Course</center></th> <th class='margin'><center>Section</center></th><th class='margin'><center>Year Enrolled</center></th> <th class='margin'><center>Add Grades</center></th>
<th class='margin'><center>View Grades</center></th>
<th class='margin'><center>Stop</center></th>
</b>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo '<td><input type="checkbox" name="del_box[]" id="chkbox" value="' . $row['id'] . '"/></td>';
echo '<td><font class="small"><center><a href="write_message.php?id=1">' . $row['fullname'] . '</a></center></font></td>';
echo '<td><font class="small"><center>' . $row['course'] . '</center></font></td>';
echo '<td><font class="small"><center>' . $row['section'] . '</center></font></td>';
echo '<td class="margin"><font class="small"><center>' . $row['year'] . '</center></font></td>';
echo '<td class="hide"><center>' . $row['username'] . '</center></td>';
echo '<td><center><a class="btn" href="add_grades.php?id=' . $row['username'] . '&course=' .$row['course'] . '"><span class="icon icon-add">&nbsp;</span></a></center></td>';
echo '<td class="margin"><center><a class="btn" href="view_grades.php?id=' . $row['username'] . '&course=' .$row['course'] . '"><span class="icon icon-grades">&nbsp;</span></a></center></td>';
echo '<td><center><a class="btn" href="stop.php?id=' . $row['id'] . '"><span class="icon icon-cancel">&nbsp;</span></a></center></td>';
echo "</tr>";
}
?>
</div>
<!-- do not use shorthand syntax if this script is going to distributed -->
<!--  we show our pagination -->
<div class="pagination"><?php echo $pagination; ?></div>


</div>
<?php include_once 'includes/footer.php';?>
</div>
</body>
</html>

One final word, notice how you prepared your second query..

 $sql = "SELECT id, fullname, course, year, section, year FROM $tbl_name LIMIT $start, $limit";
 $result = mysql_query($sql);

I added the id in the front.. without it your script is not going to work.. Is there any reasons why you can't use this query instead of the above?

 $sql = "SELECT * from ".$tbl_name."  LIMIT ".$start.", ".$limit."";

Html and php tags hybrids. When you have a php and html on the same page, it is ok to close the php , so that you server does not have to parse those html inside the echo function.

for example, these codes could have been written as html an not echoed by the script.

  echo "<table border='1' cellpadding='10' width='727'>";
  echo "<tr> <b>
  <th><input type='checkbox' name='del_all' id='del_chkbox' onClick='check_all(document.delForm.chkbox)' /></th>
  <th width='130'><center>Full Name</center></th> <th width='130'><center>Course</center></th> <th class='margin'><center>Section</center></th><th class='margin'><center>Year Enrolled</center></th> <th class='margin'><center>Add Grades</center></th>
 <th class='margin'><center>View Grades</center></th>
 <th class='margin'><center>Stop</center></th>
 </b>
 </tr>";

Edited by veedeoo: more info added

0

it really works but i'm still not getting the value of id in the url,only the value of course,,after i clicked the view grades,,really2x thank you

0

Hi,

Can you double check what is the column name on your database? This should be called id.. remember this is a case sensitive.. make sure the id in your query matched the actual mysql database column name for the id..

0

i'm sorry,,my fault,,:}it's ok now,works perfectly,,wew,,thank you veedeoo.:}

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.