Jump to content

limit results per page problem


Prank

Recommended Posts

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;

[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>
';
[/code]

Thanks in advance!

Christian
Link to comment
https://forums.phpfreaks.com/topic/3980-limit-results-per-page-problem/
Share on other sites

[!--quoteo(post=351250:date=Mar 3 2006, 01:05 AM:name=Prank)--][div class=\'quotetop\']QUOTE(Prank @ Mar 3 2006, 01:05 AM) [snapback]351250[/snapback][/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;

[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>
';
[/code]

Thanks in advance!

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

Oh, so I need to increase $screen by $rows_per_page ? increasing it by 1 wont matter?
[!--quoteo(post=352072:date=Mar 7 2006, 01:18 AM:name=XenoPhage)--][div class=\'quotetop\']QUOTE(XenoPhage @ Mar 7 2006, 01:18 AM) [snapback]352072[/snapback][/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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.