single page pagination problem
am 28.07.2006 19:58:41 von frankHi all,
this is my first attempt at using php with a db. (i'm sure you can tell
from code :-) The problem is that the result data does not display when
the 'next' link is clicked. Only the first page displays correctly. i
know this problem has been covered many times in the past, and i have
spent the last week trying to apply what others have done but it just
dosen't work. From what i've read, i think i should be using the
$_SESSION global, but i just don't understand how to do this. Any help
would be greatly appreciated.
session_start();
?>
if (isset($_POST['pageno']))
{
$pageno = $_POST['pageno'];
}
else {
$pageno = 1;
}
$db = "/var/db/iptables.db";
$handle = sqlite3_open($db);
if ((isset ($_POST['submit'])) && ($_POST['value'] == varname1 )) {
$query1 = "SELECT count (*) FROM ulog WHERE oob_prefix = 'Ping
detected'";
}elseif
((isset ($_POST['submit'])) && ($_POST['value'] == varname2 )) {
$query1 = "SELECT count (*) FROM ulog WHERE oob_prefix = 'INPUT packet
died'";
}
$result1 = sqlite3_query($handle, $query1);
while ($row = sqlite3_fetch_array($result1)){
$count = $row['count (*)'];
}
$rows_per_page = 22;
$lastpage = ceil($count/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno < 1) {
$pageno = 1;
} elseif ($pageno > $lastpage) {
$pageno = $lastpage;
} // if
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
if ($_POST['value'] == varname1 ) {
$query2 = "SELECT * FROM ulog WHERE oob_prefix = 'Ping detected'
$limit";
}elseif
($_POST['value'] == varname2 ) {
$query2 = "SELECT * FROM ulog WHERE oob_prefix = 'INPUT packet died'
$limit";
}
$result2 = sqlite3_query($handle, $query2);
while ($row = sqlite3_fetch_array($result2)) {
//This table provides the formatting for the data taken
//from the db
echo "
$field1 | $field2 | $field3 | $field4 | $field5 |
"; if ($pageno == 1) { echo " FIRST PREV "; } else { echo " "; $prevpage = $pageno-1; echo " "; } echo " ( Page $pageno of $lastpage ) "; if ($pageno == $lastpage) { echo " NEXT LAST "; } else { $nextpage = $pageno+1; echo " "; echo " "; } echo " |
sqlite3_query_close($result1);
sqlite3_query_close($result2);
sqlite3_close($handle);
?>