Jump to content


Photo

2 Guestbook Questions


  • Please log in to reply
2 replies to this topic

#1 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 28 June 2006 - 07:50 PM

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...ml4/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>


How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 28 June 2006 - 07:57 PM

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:
if ($offset < 1000) {
to the following:
if ($offset < $pages) {
$pages is the variable you setup for the max number of pages.

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

for ($i = 0; $i < $count; $i++) {
$row = mysql_fetch_array($result);
to the following:
$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
}


#3 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 28 June 2006 - 08:21 PM

Hi, Wildteen88.

thanks once again for you help, it all worked wounders.

kind regards
jeff
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users