Can some one tell me what is causing this. The result is ignoring the first record on the table and starting with the second. It is displaying 2-11, then 12-21, etc.
Please Help,
Armando
Here is the code:
<table width="70%" align="center" >
<tr>
<td><div align="center">
<h1> </h1>
</div></td>
</tr>
<tr>
<td><?php
//database values
$host = "host ";
$user = "user ";
$password = "password";
$database = "database";
$dbtable = "table";
$limit = "10"; // rows per page to return
// connect to database
$link = @ mysql_connect($host,$user,$password) or die ("Sorry <BR>\n Could not connect to the Guestbook. Please try later");
// next determine if offset has been passed to script, if not use 0
if (empty($offset))
{
$offset=1;
}
//query
$query = "SELECT * FROM $dbtable limit $offset, $limit";
// check to see if the query was successful
if (!mysql_db_query($database, $query, $link))
{
echo ("Sorry <br>\n Could not connect to the Items Cat!<BR>\n");
}
else
{
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo " There are <b>$num_results</b> in the cat <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> item:</div></th> <td> <div align=left>$row[item]</div></td>\n";
echo "</tr>\n";
echo "<TR ALIGN=CENTER VALIGN=TOP>\n";
echo "<th><div align=left>description:</div></th> <td><div align=left>$row[description]</div></td>\n";
echo "</tr>\n";
echo "<TR ALIGN=CENTER VALIGN=TOP>\n";
echo "<th><div align=left> description:</div></th> <td><div align=left>$row[description2]</div></td>\n";
echo "</TR>\n";
echo "<TR ALIGN=CENTER VALIGN=TOP>\n";
echo "<th><div align=left>price:</div></th> <td><div align=left>$row[price]</div></td>\n";
echo "</TR>\n";
echo "</tr>\n";
echo "</table><br>\n";
}
}
// next we need to do the links to other results
if ($offset >1)
{ // bypass PREV link if offset is 0
$prevoffset=$offset-5;
echo "<a href=\"$PHP_SELF?offset=$prevoffset\">PREV</a> \n";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
for ($i=1;$i<=$pages;$i++) { // loop thru
$newoffset=$limit*($i-1);
echo "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> \n";
}
// check to see if last page
if (!(($offset/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$newoffset=$offset+$limit;
echo "<a href=\"$PHP_SELF?offset=$newoffset\">NEXT</a><p>\n";
}
}
// Close the database connection
if ($link = mysql_connect($host,$user,$password))
{
mysql_close ($link);
}
?></td>
</tr>
</table>