Hi All,
I am working on a php web page to display some SQL results, and I seem to be missing something 🙂 This code renders the page correctly, but the 'pager' doesn't work, only shows the first page. Clicking next doesn't change the data, so I am thinking I am displaying the header outside of my loop ?
Second set of eyes appreciated -0
Edward
<?php
include_once 'config/constants.php';
include_once 'config/opendb.php';
// rows to return
$rowsPerPage = 20;
$pageNum = 1;
$yesterday = strftime ("%Y/%m/%d", strtotime("-2 day"));
$pretty = strftime ("%A %B %d");
$page = $_GET['page'];
print "<table style='font-family: verdana; font-size: 8pt; color: 000066;' cellpadding=5 cellspacing=1 bgcolor=FFFFFF width=\"1009\" height=\"293\" border=\"0\">";
print " <tr>";
print " <td width=\"471\" height=\"287\"><h1><img src=\"http://microbe.healthydirections.com/images/hd_bnr_TLv2.gif\" width=\"471\" height=\"123\" /></h1>";
print "<font face=arial color=000066><h1>Bounce Report </font></h1>";
print "<font face=arial color=000066><a href=\"http://microbe.healthydirections.com/bounce\">Go to Adaptive Log</a><br />";
print "<br />";
print "Showing results from $pretty <br />";
print "<br>";
print " <td width=\"522\">";
print "</td>";
print "</tr>";
print "</table>";
print "</h1>";
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
$offset = ($pageNum - 1) * $rowsPerPage;
db_connect_ecelerity(DBUSER, DBUSERPW);
$query1 = "select * FROM `bouncelog` ORDER BY `insert_date` DESC LIMIT $offset, $rowsPerPage";
$numresults=mysql_query($query1);
$numrows=mysql_num_rows($numresults);
$result = mysql_query($query1) or die('Error, lame query failed');
function makeHeaderLink($value, $key, $col, $dir) {
$out = "<a href=\"" . $_SERVER['SCRIPT_NAME'] . "?c=";
//set column query string value
switch($key) {
case "insert_date":
$out .= "1";
break;
case "message_id":
$out .= "2";
break;
case "log_type":
$out .= "3";
break;
case "to_local":
$out .= "4";
break;
case "to_domain":
$out .= "5";
break;
case "from_local":
$out .= "6";
break;
case "from_domain":
$out .= "7";
break;
case "binding_group":
$out .= "8";
break;
case "binding_name":
$out .= "9";
break;
case "bounce_phase":
$out .= "10";
break;
case "bounce_code":
$out .= "11";
break;
case "ip_address":
$out .= "12";
break;
case "bounce_message":
$out .= "13";
break;
default:
$out .= "1";
}
$out .= "&d=";
//reverse sort if the current column is clicked
if($key == $col) {
switch($dir) {
case "ASC":
$out .= "1";
break;
default:
$out .= "0";
}
}
else {
//pass on current sort direction
switch($dir) {
case "ASC":
$out .= "0";
break;
default:
$out .= "1";
}
}
//complete link
$out .= "\">$value</a>";
return $out;
}
switch($_GET['c']) {
case "1":
$col = "insert_date";
break;
case "3":
$col = "message_id";
break;
case "3":
$col = "log_type";
break;
case "4":
$col = "to_local";
break;
case "5":
$col = "to_domain";
break;
case "6":
$col = "from_local";
break;
case "7":
$col = "from_domain";
break;
case "8":
$col = "binding_group";
break;
case "9":
$col = "binding_name";
break;
case "10":
$col = "binding_phase";
break;
case "11":
$col = "bounce_code";
break;
case "12":
$col = "ip_address";
break;
case "13":
$col = "bounce_message";
break;
default:
$col = "insert_date";
}
if($_GET['d'] == "1") {
$dir = "DESC";
}
else {
$dir = "ASC";
}
if(!$link = mysql_connect("localhost", "root", "pass")) {
echo "Cannot connect to db server";
}
elseif(!mysql_select_db("ecelerity")) {
echo "Cannot select database";
}
else {
if(!$rs = mysql_query("SELECT * FROM bouncelog ORDER BY $col $dir LIMIT 500")) {
echo "Cannot parse query";
}
elseif(mysql_num_rows($rs) == 0) {
echo "No records found";
}
else {
echo "<table class=\"bordered\" cellspacing=\"0\">\n";
echo "<tr>";
echo "<th>" . makeHeaderLink("Date", "insert_date", $col, $dir) . "</th>";
echo "<th>" . makeHeaderLink("Message ID", "message_id", $col, $dir) . "</th>";
echo "<th>" . makeHeaderLink("Log Type", "log_type", $col, $dir) . "</th>";
echo "<th>" . makeHeaderLink("To Local", "to_local", $col, $dir) . "</th>";
echo "<th>" . makeHeaderLink("To Domain", "to_domain", $col, $dir) . "</th>";
echo "<th>" . makeHeaderLink("From Local", "from_local", $col, $dir) . "</th>";
echo "<th>" . makeHeaderLink("From Domain", "from_domain", $col, $dir) . "</th>";
echo "<th>" . makeHeaderLink("Binding Group", "binding_group", $col, $dir) . "</th>";
echo "<th>" . makeHeaderLink("Binding Name", "binding_name", $col, $dir) . "</th>";
echo "<th>" . makeHeaderLink("Bounce Phase", "bounce_phase", $col, $dir) . "</th>";
echo "<th>" . makeHeaderLink("Bounce Code", "bounce_code", $col, $dir) . "</th>";
echo "<th>" . makeHeaderLink("IP Address", "ip_address", $col, $dir) . "</th>";
echo "<th>" . makeHeaderLink("Bounce Message", "bounce_message", $col, $dir) . "</th>";
echo "</tr>\n";
for($i = 0; $i < $numrows; $i++)
{
$row = mysql_fetch_array($rs); //get a row from our result set
$date2 = $row['insert_date'];
$date3 = date("F-d-Y", $date2);
$ip2 = $row['ip_address'];
$host = long2ip($ip2);
if(($i % 2) == 0) {
echo "<TR bgcolor=\"#0099FF\">\n";
} else {
echo "<TR bgcolor=\"white\">\n";
}