i have this code of Pagination, actually it will retrieve all the records in my table student, what i want is to retrieve records with a reference by year level. here is the code:
thanks for your help!
<?php
if (!isset($_POST['level'])) {
$_POST['level'] = "undefine";
}
$level = $_POST['level'];
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("kp_and_harang") or die(mysql_error());
if (!(isset($_GET['pagenum']))) {
$pagenum = 1;
} else {
$pagenum = $_GET['pagenum'];
}
$data = mysql_query("SELECT id,surname,firstname,middlename,level FROM students") or die(mysql_error());
$rows = mysql_num_rows($data);
$page_rows = 2;
$last = ceil($rows / $page_rows);
if ($pagenum < 1) {
$pagenum = 1;
} elseif ($pagenum > $last) {
$pagenum = $last;
}
$max = 'limit ' . ($pagenum - 1) * $page_rows . ',' . $page_rows;
$data_p = mysql_query("SELECT *,LPAD(id,4,'0') as id FROM students $max ") or die(mysql_error());
while ($info = mysql_fetch_array($data_p)) {
echo "<tr class='tr1'>";
echo "<center>";
echo "<td class='1'>" . $info['id'] . "</td>";
echo "<td class='1'>" . $info['surname'] . ", " . $info['firstname'] . " " . $info['middlename'] . "</td>";
echo "<td class='1'>" . $info['level'] . "</td>";
echo "</center>";
echo "</tr>";
echo "<br>";
}
echo "<p>";
echo " --Page $pagenum of $last-- <p>";
if ($pagenum == 1) {
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
echo "----";
$previous = $pagenum - 1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> ";
}
echo " ---- ";
if ($pagenum == $last) {
} else {
$next = $pagenum + 1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> ";
echo "----";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> ";
}
?>