Hi,
I am writing a guestbook script and would like to tidy up the results of a MySql query into multiple pages, if there are more than 10 results.
here is the code so far:
<?php require("../inc/header.inc"); ?>
<table width="70%" align="center" >
<tr>
<td><div align="center">
<h1>Guestbook</h1>
</div></td>
</tr>
<tr>
<td><?php
//database values
$host = "localhost";
$user = "user";
$password = "password";
$database = "database";
$dbtable = "gbook";
// connect to database
$link = @ mysql_connect($host,$user,$password) or die ("Sorry <BR>\n Could not connect to the Guestbook. Please try later");
//query
$query = "SELECT * FROM $dbtable";
// check to see if the query was successful
if (!mysql_db_query($database, $query, $link))
{
echo ("Sorry <br>\n Could not connect to the Guestbook!<BR>\n");
}
else
{
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo " There are <b>$num_results</b> messages in the guest book <br>\n<br>\n";
for ($i=0; $i <$num_results; $i++)
{
while ($row = mysql_fetch_array($result))
{
echo "<table width=345 border=1 cellpadding=0 cellspacing=0 bordercolor=E7E7E7>\n";
echo "<TR ALIGN=CENTER VALIGN=TOP>\n";
echo "<th><div align=left> Name:</div></th> <td> <div align=left>$row[name]</div></td>\n";
echo "</tr>\n";
echo "<TR ALIGN=CENTER VALIGN=TOP>\n";
echo "<th><div align=left>Email:</div></th> <td><div align=left>$row[email]</div></td>\n";
echo "</tr>\n";
echo "<TR ALIGN=CENTER VALIGN=TOP>\n";
echo "<th><div align=left> Date:</div></th> <td><div align=left>$row[pdate]</div></td>\n";
echo "</TR>\n";
echo "<TR ALIGN=CENTER VALIGN=TOP>\n";
echo "<th><div align=left>Country:</div></th> <td><div align=left>$row[country]</div></td>\n";
echo "</TR>\n";
echo "<th><div align=left>Message:</div></th> <td><div align=left>$row[comment]</div></td>\n";
echo "</tr>\n";
echo "</table><br>\n";
}
}
}
// Close the database connection
if ($link = mysql_connect($host,$user,$password))
{
mysql_close ($link);
}
?></td>
</tr>
</table>
<?php require("../inc/footer.inc"); ?>
I dont know where to start othere than I have already calculated how many rows of data there are..... which I think is the first step!
I'm not looking for someone to write the code needed.... just someone to point the way 🙂
Thanks