Current location: Hot Scripts Forums » Programming Languages » PHP » pagination problem


pagination problem

Reply
  #1 (permalink)  
Old 09-06-10, 03:28 AM
esandra esandra is offline
Newbie Coder
 
Join Date: Aug 2009
Posts: 47
Thanks: 1
Thanked 0 Times in 0 Posts
pagination problem

i really can't tell what's wrong with my pagination script..to say the least it isn't working.when i click a number that (the pagination) it wont show me the files that its supposed to. :shrug: ive been looking at this thing the whole week i cant find out what's wrong with this thing

if((isset($_POST['tcl'])) && (isset($_POST['date']))){ //main, disregard top 2 same posts
$tcl=$_POST['tcl'];
$date=$_POST['date'];

//pagination
$page_name="view.php";

$start=$_GET['start']; //global variable if OFF
if(!($start > 0)) { // This variable is set to zero for the first page
$start = 0;
}
$eu = ($start -0);
$limit = 1;

$this1 = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;

$query2=" select * from arrastre where `tcl` = '" . $tcl. "' and `date` = '" . $date . "'";
$result2=mysql_query($query2);
echo mysql_error();
$nume=mysql_num_rows($result2);

$query = "select * from `arrastre` where `tcl` = '" . $tcl. "' and `date` = '" . $date . "' order by `tcl` asc";
$result = mysql_query($query) or die(mysql_error());

$totalcollections = 0;
$y=0; //for bgcolor
while($row=mysql_fetch_array($result)){
if($y % 2==0){
$a="#999";
}
else{
$a="#FFF";
}
$y++;
$totalcollections += $total;

$orno=$row['orno'];
$billnmbr=$row['billnmbr'];
$payor=$row['payor'];
$arrastre=$row['arrastre'];
$wharfage=$row['wharfage'];
$total=$row['total'];
$date=$row['date'];

$totformat = number_format($totalcollections,2);
$arrformat = number_format($arrastre, 2);
$wharformat = number_format($wharfage, 2);
$totalformat = number_format($total, 2);

$explode_bill=explode("-",$billnmbr);

$bill1 = 0;
$bill2 = 0;

$bill1 = $explode_bill[0];
$bill2 = $explode_bill[1];

if(strlen($bill2)==1){
$rep = "00000";
$billnmbr = $bill1."-".$rep."".$bill2;
}
elseif(strlen($bill2)==2){
$rep = "0000";
$billnmbr = $bill1."-".$rep."".$bill2;
}
elseif(strlen($bill2)==3){
$rep = "000";
$billnmbr = $bill1."-".$rep."".$bill2;
}
elseif(strlen($bill2)==4){
$rep = "00";
$billnmbr = $bill1."-".$rep."".$bill2;
}
elseif(strlen($bill2)==5){
$rep = "0";
$billnmbr = $bill1."-".$rep."".$bill2;
}
else{
$rep = "000000";
$billnmbr = $bill1."-".$rep."".$bill2;
}
?>//this is my display
<tr bgcolor="<?php echo $a;?>">
<td height="20" align="center"><?php echo $orno;?>
<td align="left"><?php echo $billnmbr;?>
<td align="left"><?php echo $payor;?>
<td align="right"><?php echo $arrformat;?>
<td align="right"><?php echo $wharformat;?>
<td align="right"><?php echo $totalformat;?>
</tr>
<?php }

?>
<tr>
<td colspan="4">
<td align="right">on page total:
<td align="right"><?php echo $totformat;?>
</tr>
</table>
</center>
<div align="center">
<?php
$p_limit=5; // This should be more than $limit and set to a value for which links are to be breaked
$p_f=$_GET['p_f']; // To take care global variable if OFF
if(!($p_f > 0)) { // This variable is set to zero for the first page
$p_f = 0;
}
$p_fwd=$p_f+$p_limit;
$p_back=$p_f-$p_limit;
//////////// End of variables for advance paging ///////////////
/////////////// Start the buttom links with Prev and next link with page numbers /////////////////
if($p_f<>0){print "<a href='$page_name?start=$p_back&p_f=$p_back'>PREV $p_limit</a>"; }
//// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
elseif($back >=0 and ($back >=$p_f)) {
print "<a href='$page_name?start=$back&p_f=$p_f'>PREV</a>";
}
//////////////// Let us display the page links at center. We will not display the current page as a link ///////////
for($i=$p_f;$i < $nume and $i<($p_f+$p_limit);$i=$i+$limit){
if($i <> $eu){
$i2=$i+$p_f;
echo " <a href='$page_name?start=$i&p_f=$p_f'>$i</a> ";
}
else { echo "<font face='Verdana' size='2' color=red>$i</font>";} /// Current page is not displayed as link and given font color red
}
///////////// If not in the last page then Next link will be displayed. Here we check that /////
if($this1 < $nume and $this1 <($p_f+$p_limit)) {
print "<a href='$page_name?start=$next&p_f=$p_f'>NEXT</a>";}
elseif($p_fwd < $nume){
print "<a href='$page_name?start=$p_fwd&p_f=$p_fwd'>NEXT $p_limit</a>";
}}
?></div>
Reply With Quote
  #2 (permalink)  
Old 09-06-10, 05:06 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
Hi,

I don't see your query using the paging variables. So if I gusess right you will always see the first page, no matter what page number you click. Your query should be altered to be something like this:

PHP Code:

$offset = ($start) * $rowsPerPage;

$query "select * from `arrastre` where `tcl` = '" $tcl"' and `date` = '" $date "'LIMIT ".$offset","$rowsPerPage ." order by `tcl` asc"
Don't forget you need to set $rowsPerPage to the number of records you want per page.
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
login, roles problem dbrook007 ASP.NET 10 11-10-06 03:42 PM
Form Display Problem neevrap02 Visual Basic 1 09-05-06 05:18 AM
Pagination Problem lppa2004 PHP 1 03-24-06 07:54 PM
Pagination Problem fraggle PHP 1 02-27-06 08:23 AM
Asp and Microsoft Access 2002 problem gop373 ASP 2 10-06-04 09:13 AM


All times are GMT -5. The time now is 08:19 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.