|
Posted by frank on 07/28/06 17:58
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();
?>
<html>
<body>
<form action="<? $_SERVER['PHP SELF']; ?>" method="POST">
<input type="radio" name="value" value="varname1">varname1
<input type="radio" name="value" value="varname2">varname2
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
<?
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 "<table width=1800 cellpadding=1 border=0 colgroup span=32>";
echo "<col width=40></col>"; //ID
echo "<col width=120></col>"; //Date/Time
echo "<col width=120></col>"; //Message
echo "<col width=32></col>"; //In Interface
echo "<col width=32></col>"; //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 "</colgroup>";
echo "<tr bgcolor=$color>
<td>$field1</td>
<td>$field2</td>
<td>$field3</td>
<td>$field4</td>
<td>$field5</td>
</tr>";
}
echo "<table width=500 align=center cellpadding=2 border=2>";
echo "<tr align=center><td>";
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> ";
}
echo " ( Page $pageno of $lastpage ) ";
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> ";
}
echo "</tr></td>";
echo "</table>";
sqlite3_query_close($result1);
sqlite3_query_close($result2);
sqlite3_close($handle);
?>
</body>
</html>
Navigation:
[Reply to this message]
|