Jump to content


Photo

limit results per page problem


  • Please log in to reply
8 replies to this topic

#1 Prank

Prank
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationSydney, AUS

Posted 03 March 2006 - 05:05 AM

Hi Guys,

I am trying to return 30 results per page with a simple 'next' link to the next 30... I have no idea why it wont work, I have passed the value of '$screen' through a form (and retrieved with $_POST) and have passed it in a link trader_convert.php?screen=$newscreen (and retrieved with $_REQUEST['screen]).

It wont go to the next 30 results. Also, it seems to start at the 2nd record also, it will output id's from 2 - 30.

Heres the code;

// Snip

db_connect();

if (!isset($_POST['screen'])) {
    $screen = 0;
} else {
    $screen = $_POST['screen'];
}
$start = $screen * $rows_per_page;
$rows_per_page = 30;
$q = "SELECT * FROM user_rate_trade LIMIT $start , $rows_per_page";
$r = mysql_query($q)or die(mysql_error());
$row = mysql_fetch_assoc($r);
$total_records = mysql_num_rows($r);
$pages = ceil($total_records / $rows_per_page);

while($row = mysql_fetch_assoc($r)) {

    $date = strtotime($row['userdate']);

    echo ''.$row['userrateid'].'. '.$row['userdate'].' = '.$date.'<br/>';

}

$newscreen = $screen + 1;
echo '
<form method="post" action="trader_convert.php">
<input type="hidden" name="screen" value="'.$newscreen.'" />
<input type="submit" name="submit" />
</form>
';

Thanks in advance!

Christian
The way to a mans stomach is through his heart.

#2 grim1208

grim1208
  • Members
  • PipPipPip
  • Advanced Member
  • 89 posts

Posted 03 March 2006 - 07:19 AM

[!--quoteo(post=351250:date=Mar 3 2006, 01:05 AM:name=Prank)--][div class=\'quotetop\']QUOTE(Prank @ Mar 3 2006, 01:05 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hi Guys,

I am trying to return 30 results per page with a simple 'next' link to the next 30... I have no idea why it wont work, I have passed the value of '$screen' through a form (and retrieved with $_POST) and have passed it in a link trader_convert.php?screen=$newscreen (and retrieved with $_REQUEST['screen]).

It wont go to the next 30 results. Also, it seems to start at the 2nd record also, it will output id's from 2 - 30.

Heres the code;

// Snip

db_connect();

if (!isset($_POST['screen'])) {
    $screen = 0;
} else {
    $screen = $_POST['screen'];
}
$start = $screen * $rows_per_page;
$rows_per_page = 30;
$q = "SELECT * FROM user_rate_trade LIMIT $start , $rows_per_page";
$r = mysql_query($q)or die(mysql_error());
$row = mysql_fetch_assoc($r);
$total_records = mysql_num_rows($r);
$pages = ceil($total_records / $rows_per_page);

while($row = mysql_fetch_assoc($r)) {

    $date = strtotime($row['userdate']);

    echo ''.$row['userrateid'].'. '.$row['userdate'].' = '.$date.'<br/>';

}

$newscreen = $screen + 1;
echo '
<form method="post" action="trader_convert.php">
<input type="hidden" name="screen" value="'.$newscreen.'" />
<input type="submit" name="submit" />
</form>
';

Thanks in advance!

Christian
[/quote]
you could use a link and do something like this instead of a form
<a href="trader_conver.php?screen=<?php $screen = $screen + 30; print $screen;?>">

grim1208
New Web Projects

#3 Prank

Prank
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationSydney, AUS

Posted 03 March 2006 - 08:50 AM

[!--quoteo(post=351264:date=Mar 3 2006, 06:19 PM:name=grim1208)--][div class=\'quotetop\']QUOTE(grim1208 @ Mar 3 2006, 06:19 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
you could use a link and do something like this instead of a form
<a href="trader_conver.php?screen=<?php $screen = $screen + 30; print $screen;?>">
[/quote]

Oh, so I need to increase $screen by $rows_per_page ? increasing it by 1 wont matter?
The way to a mans stomach is through his heart.

#4 Prank

Prank
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationSydney, AUS

Posted 04 March 2006 - 12:54 PM

Anyone?

You can view the script's output and the problem I am experiencing [a href=\"http://www.skylinesaustralia.com/trader_convert.php\" target=\"_blank\"]here[/a]

Thanks
The way to a mans stomach is through his heart.

#5 Kingskin

Kingskin
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 04 March 2006 - 01:18 PM

Well, you have this line:

$start = $screen * $rows_per_page;

before you have defined the value of $rows_per_page

dont know if thats the problem but it just jumped out at me.

#6 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 04 March 2006 - 04:04 PM

Yes, that's exactly the problem, you're multiplying by $rows_per_page before you've set it to 30!

#7 Prank

Prank
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationSydney, AUS

Posted 06 March 2006 - 02:52 AM

Love your work guys!

Thanks very much!

Christian
The way to a mans stomach is through his heart.

#8 XenoPhage

XenoPhage
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 06 March 2006 - 02:18 PM

As an aside, there is some decent paginator code here : [a href=\"http://tkap.org/paginator/\" target=\"_blank\"]http://tkap.org/paginator/[/a]

I've used this in several project and it comes in quite handy...
--
[a href=\"http://blog.godshell.com\" target=\"_blank\"]XenoPhage[/a]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Something mysterious is formed, born in the silent void. Waiting alone and unmoving, it is at once still and yet in constant motion. It is the source of all programs. I do not know its name, so I will call it the Tao of Programming.[/quote]

#9 Prank

Prank
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationSydney, AUS

Posted 07 March 2006 - 05:17 AM

[!--quoteo(post=352072:date=Mar 7 2006, 01:18 AM:name=XenoPhage)--][div class=\'quotetop\']QUOTE(XenoPhage @ Mar 7 2006, 01:18 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
As an aside, there is some decent paginator code here : [a href=\"http://tkap.org/paginator/\" target=\"_blank\"]http://tkap.org/paginator/[/a]

I've used this in several project and it comes in quite handy...
[/quote]

Nice, thanks for that.
The way to a mans stomach is through his heart.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users