include ("config.inc");
//connect
mysql_pconnect( "$host", "$username", "$password")
or die( "Unable to connect to SQL server");
mysql_select_db( "$db_name") or die( "Unable to select database");
$numresults=mysql_query("SELECT name, date, email, comment FROM guestbook");
$numrows=mysql_num_rows($numresults)
or die ("query 1 failed");
if (empty($offset)) {
$offset=0;
}
$query = "SELECT name, date, email, comment FROM guestbook order by date DESC limit $offset,$limit";
$result = mysql_query ($query)
or die ("query 2 failed");
while ($row = mysql_fetch_row ($result))
{
for ($i = 0; $i < mysql_num_fields ($result); $i++)
{
if ($i > 0)
print (" ");
if ($i == 0){
print "Name: ";
}
else if ($i == 1){
print "Date: ";
}
else if ($i == 2){
print "Email: ";
}
else{
print "Comment: ";
}
print "" . ($row[$i]) . "";
}
print "
";
print ("");
}
if ($offset >= 3) {
$prevoffset = $offset - $limit;
print "PREV \n";
}
$pages=intval($numrows/$limit);
if ($pages < ($numrows/$limit)){
$pages=($pages + 1);
}
for ($i = 1; $i <= $pages; $i++) {
$newoffset = $limit*($i-1);
if ($newoffset == $offset) {
print "$i \n";
} else {
print "$i \n";
}
}
//show next if not last
if (! ( ($offset/$limit) == ($pages - 1) ) && ($pages != 1) ) {
$newoffset = $offset+$limit;
print "NEXT \n";
}
?>
|