hi everybody,
I am doing pagination.
if I set the limit to 5 and the no of result is 30, then 6 pages is shown as the overall page).
however, only the first 5 results is shown.
How should I change the code?
many thanks
<?php
/* call this script "advs.php" */
//if(!$c) {
if(!$_GET['c']) {
//"c" variable to $_GET['c'] and the "all" "any" and "none" variables to $_POST['all']
?>
<?php
$all= $_POST['all'] ;
$any= $_POST['any'] ;
$none=$_POST['none'] ;
//this makes sure the page number isn't below one, or more than our maximum pages
$pageno = (int)$pageno;
if ($pageno > $lastpage) {
$pageno = $lastpage;
}
if ($pageno < 1) {
$pageno = 1;
}
mysql_connect("localhost","root","rootroot");
MySQL_select_db("coas5");
if((!$all) || ($all == "")) { $all = ""; } else { $all = "+(".$all.")"; }
if((!$_POST['all'] ) || ($_POST['all'] == "")) { $_POST['all'] = ""; } else { $_POST['all'] = "+(".$_POST['all'] .")"; }
if((!$any) || ($any == "")) { $any = ""; }
if((!$none) || ($none == "")) { $none = ""; } else { $none = "-(".$none.")"; }
$query = " SELECT count(*),
MATCH(subject, learningArea, noofstudents, topic, ability) AGAINST ('$all $none $any' IN BOOLEAN MODE)
FROM lesson
WHERE MATCH(subject, learningArea, noofstudents, topic, ability) AGAINST ('$all $none $any' IN BOOLEAN MODE) AND lesson.verified= 'yes' " ;
$artm1 = MySQL_query($query);
$query_data = mysql_fetch_row($artm1);
$numrows = $query_data[0];
$rows_per_page = 2;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno > $lastpage) {
$pageno = $lastpage;
}
if ($pageno < 1) {
$pageno = 1;
}
//This sets the range to display in our query
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query = " SELECT *,
MATCH(subject, learningArea, noofstudents, topic, ability) AGAINST ('$all $none $any' IN BOOLEAN MODE)
FROM lesson
WHERE MATCH(subject, learningArea, noofstudents, topic, ability) AGAINST ('$all $none $any' IN BOOLEAN MODE) AND lesson.verified= 'yes' $limit" ;
$artm1 = MySQL_query($query);
if(MySQL_num_rows($artm1) > 0) {
echo "<b>Lesson Plans Matches</b><br>";
echo "<table>";
echo "<table border='1'>";
echo "<tr><td>Lesson ID </td><td>Subject </td><td>Learning area</td> <td>Topic</td> <td>Time period</td><td>Ability</td></tr>";
while($artm2 = MySQL_fetch_array($artm1)) {
echo "<td><a href='customise1.php?lessonID= {$artm2['lessonID']}; '> {$artm2['lessonID']}</a></td>";
//echo "<td>{$artm2['lessonID']}</td>";
echo "<td>{$artm2['subject']}</td>";
echo "<td>{$artm2['learningArea']}</td>";
echo "<td>{$artm2['topic']}</td>";
echo "<td>{$artm2['minutes']}</td>";
echo "<td>{$artm2['ability']}</td></tr>";
}
echo "</table>";
}
else {
echo "No Results were found in this category.<br>";
}
if ($pageno == 1) {
echo " FIRST PREV ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
$prevpage = $pageno-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
}
//Next we inform the user of his current position in the sequence of available pages.
echo " ( Page $pageno of $lastpage ) ";
//This code will provide the links for any following pages.
if ($pageno == $lastpage) {
echo " NEXT LAST ";
} else {
$nextpage = $pageno+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";
} // if
}
echo "<br>";
?>