Jump to content

2 Guestbook Questions


spires

Recommended Posts

Hi, I'm building my first guestbook and have come across 2 problems.

[a href=\"http://www.spirestest.com/login2\" target=\"_blank\"]My Webpage[/a]

1st, the database will not add the latest post to the front (1st page), They all attach to the end of the rest of the posts. I have tryed 'ORDER by DATE ASC' 'ORDER by DATE DESC' and 'ORDER by DATE'

None of these seem to work.


2nd, I've built a navigation for the guestbook. The PREV button and the Numbers all work fine. But i dont know how to get the NEXT button to not display on the final page. At the moment you can go upto page 1000.

I hope this all makes sence. please goto [a href=\"http://www.spirestest.com/login2\" target=\"_blank\"]My Webpage[/a]
and click on guest book.

Any help would be great.
Thanks

Here is my code.

<?php
include('db.php');
include('validation.php');
?>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>GuestBook</title>
<link href="../login.css" rel="stylesheet" type="text/css">
</head>

<body leftmargin="0" topmargin="0">
<center>
<table width="800" cellpadding="0" cellspacing="0">
<tr>
<td><div align="left"><a href="index.php" class="link">Click here to go back to the entrance </a></div></td>
<td align="right"><a href="sign.php" class="link">Click here to sign our guestbook</a> </td>
</tr>
<tr><td colspan="2"><br>
<?php

$limit=5;
$numresults=mysql_query("SELECT name, email, comments FROM guestbook")
or die("query 1 failed");
$numrows=mysql_num_rows($numresults);


if (empty($offset)) {
$offset=0;
}


$query = "SELECT * FROM guestbook order by DATE ASC limit $offset,$limit";
$result = mysql_query($query)
or die ("query 2 failed");


echo '<center>';
echo '<table class="TLRB_border" width="400" cellpadding="5" cellspacing="0">
<tr>
<td bgcolor="#CCCCCC" class="title">
Guestbook Entries
</td>
</tr>
</table>
<center>';


$count = mysql_num_rows($result);

for ($i = 0; $i < $count; $i++) {
$row = mysql_fetch_array($result);


echo '<center>
<table class="TLRB_border" width="400" cellpadding="5" cellspacing="0">
<TR><TD width="200" class="bgbgrey">Date:</TD>
<TD width="200" class="bggrey">'.$row['date'].'</TD></TR>
<TR><TD width="200" class="bgbwhite">Name:</TD>
<TD width="200" class="bgwhite">"'.$row['name'].'"</TD></TR>
<TR><TD width="200" class="bgbgrey">Email:</TD>
<TD width="200" class="bggrey"><a href="mailto:"$mail">'.$row['email'].'</a></TD></TR>
<TR><TD class="bgbwhite">Comments:</TD></TR>
<TR><TD class="bggrey" colspan="2">'.$row['comments'].'</TD></TR>';

echo "</TR>\n";
echo '</table>';
echo '<table width="390" height="5" bgcolor="#CCCCCC">
<tr>
<td></td>
</tr>';
echo '</table>';
echo '</center>';
echo "<br>";

}
?>


<table width="400" cellpadding="0" cellspacing="0">
<tr>
<td align="center" width="30">
<?php // prev
if ($offset >= 5) {
$prevoffset=$offset-5;
print "<a href=\"$PHP_SELF?offset=$prevoffset\">PREV</a> &nbsp; \n";
}
?>
</td>
<td align="center">
<?php
// nums
$pages = intval($numrows/$limit);

if ($numrows%$limit) {
$pages++;
}

for ($i=1; $i<=$pages; $i++) {
$newoffset = $limit*($i-1);
print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> &nbsp; \n";
}
?>
</td>
<td align="center" width="30">
<?php
// next
if ($offset < 1000) {
$newoffset = $offset+$limit;
print "<a href=\"$PHP_SELF?offset=$newoffset\">NEXT</a><p>\n";
}

?>
</td>
</tr>
</table>

</td>
</tr>
</table>
</center>
</body>
</html>

Link to comment
Share on other sites

I'd use the id field if you have set one up, rather than ordering by date. adn you'll want to use this:
ORDER by `post_id` DESC

About your pages thing you'll probably want to change this:
[code]if ($offset < 1000) {[/code]
to the following:
[code]if ($offset < $pages) {[/code]
$pages is the variable you setup for the max number of pages.

Also you might want to chnage this:
[code]$count = mysql_num_rows($result);

for ($i = 0; $i < $count; $i++) {
$row = mysql_fetch_array($result);[/code]
to the following:
[code]$count = mysql_num_rows($result);

if($count < 1)
{
    echo "No entries in guestbook"
}
else
{
    while($row = mysql_fetch_array($result);

    // rest of your guestbook code here
}[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.