分页形式的PHP

i have this code :

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
body {
background-image: url(../images/paper_03.png);
}
form {
background-image: url(../images/paper_02.png);
}
</style>
</head>
<?php

require("../function.php");
// echo sizeof($_SESSION['liste']);



?>
<body >
<form name="log"  method="post"  style="position: absolute; top:50px; left: 320px; width: 600px; height: 100%;" >

                        <table BORDER=2 style="position: relative; top:15px; left: 3px;" >
                        <TR> 
                         <TH style="width:100px"><font color="blue">Date</font></TH> 
                         <TH style="width:400px"><font color="blue">Location</font></TH> 
                          <TH style="width:400px"><font color="blue">Job Title</font></TH> 
                         <TH style="width:300px"><font color="blue">Company</font></TH> 
                        </TR>
                        <?php
                        session_start();
                        for($i=0;$i<sizeof($_SESSION['liste']);$i++){
                        ?>
                        <TR>
                        <td ><center><label><?php echo $_SESSION['liste'][$i]['date']; ?></label></center></td> 
                         <td ><label><?php echo $_SESSION['liste'][$i]['region'].','.$_SESSION['liste'][$i]['city'].','.$_SESSION['liste'][$i]['state']; ?></label></td> 
                         <td ><center><label><?php echo $_SESSION['liste'][$i]['title']; ?></label></center></td> 
                         <td ><center><label><?php echo $_SESSION['liste'][$i]['comapany_name']; ?></label></center></td> 
                        </TR>
                        <?php
                        }
                        ?>
                        </table>


</form>

</body>
</html> 

i have a form i want that every 10 results be displayed togother ie add the pagination to my form with two icons ( next, previous ).

  • can i do this only with php?
  • do i need ajax in this work?

If you use mysql this should work:

$page = $_GET['page'];
$query = mysql_query("SELECT * FROM some_table LIMIT $page, 10");

And do some work with $query variable, your links should be something like this:

<a href="/somefile.php?page=<?= $current_page + 1;?>">Next</a>
  1. Pass a $liststart value in as a parameter to your code (get it with $liststart = $_REQUEST['liststart']).
  2. Then adjust your loop to loop from $liststart to $liststart+10.
  3. Make a button that onClick, goes to your code above with the new $liststart value. for example for the 'next' button on the first page, use echo "' onClick='location.href=\"yourcodeabove.php?liststart=".$liststart+10."\";'>";

or if you prefer, you could do it without javascript by making the next and prev buttons their own forms. like this:

<FORM METHOD="LINK" ACTION="yourcodeabove.php?liststart="<?php $liststart+10 ?>">
<INPUT TYPE="submit" VALUE="next->">
</FORM>

close out your other form first (which doesn't look like it needs to be a form actually... could be a div just as well). forms usually have 'actions' and are submitted with buttons but since you'll have 2 buttons (next and prev) each could be their own form with either the javascript onClick or the form method.