Jump to content

PAGINATION ISSUE


soulstrut

Recommended Posts

Hello. Avid PHP'er here. I recently switched servers and found that some of my PHP code is not compatible with PHP 5. Especially my pagination script. The database displays the category results but displays the same records when the next button is pushed. I am about to bash my head in. If any one can help, it would be greatly appreciated.

<?php

$category = $_GET['category'];
echo "<b>$category</b>";

?>

<?

/* db info */


$pagelimit = "10";

$strSQL = mysql_query("SELECT * FROM $table WHERE category='$category'");


$totalrows = mysql_num_rows($strSQL);


$pagenums = ceil ($totalrows/$pagelimit);

if ($page==''){
$page='1';
}

$start = ($page-0) * $pagelimit;


echo "<span class=soulradio2><b>" . $totalrows . " matches found</b></span><br><br>\n";

$starting_no = $start + 1;

if ($totalrows - $start < $pagelimit) {
$end_count = $totalrows;
} elseif ($totalrows - $start >= $pagelimit) {
$end_count = $start + $pagelimit;
}


echo "<span class=soulradio>Results $starting_no to $end_count shown.</span><br>\n";



$query="SELECT * FROM review_items WHERE category='$category' Order By item_name LIMIT $start,$pagelimit";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();



$i=0;
while ($i < $num) {

$item_name=mysql_result($result,$i,"item_name");
$item_id=mysql_result($result,$i,"item_id");
$Title=mysql_result($result,$i,"Title");
$item_image=mysql_result($result,$i,"item_image");
$category=mysql_result($result,$i,"category");
$Year=mysql_result($result,$i,"Year");
$Lable=mysql_result($result,$i,"Lable");
$item_desc=mysql_result($result,$i,"item_desc");

//cut the string
$substring = substr($item_desc,0,200);

?>
<? echo "<table width=100% border=0 cellspacing=4 cellpadding=0>
<tr>
<td width=10%><div class=blur><img src=$item_image border=1 width=120 height=120>
</div></td>
<td width=90%><span class=featuretext><b>$item_name - <a href='review/review_insert.php?item_id=$item_id'>$Title</a></B></span><br>
<span class=featuretext>$Lable | $Year</span><p>
<span class=soulradio2>

$substring ... <a href='review/review_insert.php?item_id=$item_id'><strong>More</strong></a></span>

</span>


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

<table width=100% border=0 cellspacing=0 cellpadding=0>
<tr>
<td background=../../images/reviews/dotted_line.gif><img src=../../images/transparent.gif width=2 height=1></td>
</tr>
</table>";


++$i;
}
/* lets say you're set to show 5 results per page and your script comes out with 7 results.
this will allow your script to say next2 if you're on the first page and previous5 if you're on the second page. */

if ($totalrows - $end_count > $pagelimit) {
$var2 = $pagelimit;
} elseif ($totalrows - $end_count <= $pagelimit) {
$var2 = $totalrows - $end_count;
}

$space = " ";

// previous link (make sure to change yourpage.php to the name of your page)
if ($page>1) {
echo "« <span class=featuretext><a href='list.php?category=$category&page=".($page-1)."' class=main>Previous" . $space . $pagelimit . "</a></span>" . $space . $space . "";
}

// dynamic page number links (make sure to change yourpage.php to the name of your page)

for ($i=1; $i<=$pagenums; $i++) {
if ($i!=$page) {
echo " <span class=featuretext><a href='list.php?category=$category&page=$i' class=main>$i</a></span>";
}
else {
echo " <span class=featuretext><b>$i</b></span>";
}
}


// next link (make sure to change yourpage.php to the name of your page)

if ($page<$pagenums) {
echo "" . $space . $space . $space . $space . " <span class=featuretext><a href='list.php?category=$category&page=".($page+1)."' class=main>Next " . $var2 . "</a></span> »";
}


?>

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.