hey people,
ive got stuck on a problem, the problem being, my paging code doesnt seem to be working, it will display the next or previous links but when they are clicked, it loads the rows that were already there.
my codes a bit long, but hopefuly your be able to make sence of it:
<?php
$cat = $_GET['cat'];
// rows to return
$limit = 15;
// Build SQL Query
$query = "select * from $TableName where category = '$cat' order by id DESC";
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
// If we have no results
if ($numrows == 0) {
echo '<form name="form1" id="form1">
<select name="cat" onchange="MM_jumpMenu(\'parent\',this,0)">
<option value="#">Select a Category</option>';
//Select Database Entries
$result=mysql_query("SELECT Category FROM $TableName GROUP BY Category DESC");
//Display Results
if ( $_GET['pass'] == $password ){
while($row=mysql_fetch_array($result))
print '<option value="' . $_SERVER['PHP_SELF'] . '?pass='.$password.'&cat='.$row['Category'].'">'.$row['Category'].'</option>';
}
else {
while($row=mysql_fetch_array($result))
print '<option value="' . $_SERVER['PHP_SELF'] . '?menu=gallery&cat='.$row['Category'].'">'.$row['Category'].'</option>';
}
echo '</select></form>
<b>Latest 5 Photos:</b><br><br>';
//Is Password Set?
if ( $_GET['pass'] == $password ){
$deleteLink1 = ': <a href="deleteentry.php?id=';
$deleteLink2 = '">delete</a> :';
}
else {
$deleteLink1 = '<!--';
$deleteLink2 = '-->';
}
//Select Database Entries
$result=mysql_query("SELECT * FROM $TableName ORDER BY id DESC LIMIT 5");
//Display Results
while($row=mysql_fetch_array($result))
print '
<script language="JavaScript">
<!--
function Enlarge'.$row['id'].'(){
var popurl="'.$row['Enlarged'].'"
winpops=window.open(popurl,"","width=500,height=450,resizable=yes")
}
-->
</script>
<div class="divIMG">
<table width="120" height="210" cellpadding="0" cellspacing="1">
<tr valign="top">
<td>
<div align="center" class="framedimg"><a href="javascript:Enlarge'.$row['id'].'()">'.$row['Thumbnail'].'</a></div>
<div align="center">'.$deleteLink1.''.$row['id'].'&files='.$row['Filename'].''.$deleteLink2.'</div>
</td>
</tr>
</table>
</div>
';
}
// next determine if s has been passed to script, if not use 0
if (empty($s)) {
$s=0;
}
// get results
$query .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query");
// if we have result/s begin to show results set
if ($numrows >= 1) {
echo '< <a href="index.php?menu=gallery">back</a> ';
echo "<b>Photo Category:</b> ".$cat."<br><br>";
$count = 1 + $s ;
}
//Is Password Set?
if ( $_GET['pass'] == $password ){
$deleteLink1 = ': <a href="deleteentry.php?id=';
$deleteLink2 = '">delete</a> :';
}
else {
$deleteLink1 = '<!--';
$deleteLink2 = '-->';
}
// now display the results returned
while ($row= mysql_fetch_array($result)) {
//Set result character limits
echo '
<script language="JavaScript">
<!--
function Enlarge'.$row['id'].'(){
var popurl="'.$row['Enlarged'].'"
winpops=window.open(popurl,"","width=500,height=450,resizable=yes")
}
-->
</script>
<div class="divIMG">
<table width="120" height="210" cellpadding="0" cellspacing="1">
<tr valign="top">
<td>
<div align="center" class="framedimg"><a href="javascript:Enlarge'.$row['id'].'()">'.$row['Thumbnail'].'</a></div>
<div align="center">'.$deleteLink1.''.$row['id'].'&files='.$row['Filename'].''.$deleteLink2.'</div>
</td>
</tr>
</table>
</div>';
$count++ ;
}
$currPage = (($s/$limit) + 1);
//break before paging
echo "<br /><br />";
//do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
if ($numrows >= 1) {
print " <a href=\"$PHP_SELF?menu=gallery&cat=$cat&s=$prevs\"><<Prev ".$limit."</a>  ";
}
}
//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++;
}
// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$news=$s+$limit;
if ($numrows >= 1) {
echo " <a href=\"$PHP_SELF?menu=gallery&cat=$cat&s=$news\">Next ".$limit." >></a>";
}
}
$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
if ($numrows >= 1) {
echo "<br><p>Showing results $b to $a of $numrows</p>";
}
?>
thats only the bit that has stuff to do with paging.
can anyone see any obvious mistakes?
thanks.