single page pagination problem

single page pagination problem

am 28.07.2006 19:58:41 von frank

Hi 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();
?>





varname1
varname2





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 "";
echo ""; //ID
echo ""; //Date/Time
echo ""; //Message
echo ""; //In Interface
echo ""; //Out Interface

$field1 = $row["id"];
$field2 = $row["oob_time_sec"];
$field3 = $row["oob_prefix"];
$field4 = $row["oob_in"];
$field5 = $row["oob_out"];

//Add color based on result
if ($field3 == "Ping detected"){
$color = "#6666FF";

}elseif

($field3 == "Invalid packet"){
$color = "#CC66FF";

}elseif

($field3 == "INPUT packet died"){
$color = "#FF0066";
}

echo "";
echo "





";
}

echo "
$field1 $field2 $field3 $field4 $field5
";
echo "";
echo "
";

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);

?>