Prank Posted March 3, 2006 Share Posted March 3, 2006 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]// Snipdb_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 Link to comment Share on other sites More sharing options...
grim1208 Posted March 3, 2006 Share Posted March 3, 2006 [!--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]// Snipdb_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] Quote Link to comment Share on other sites More sharing options...
Prank Posted March 3, 2006 Author Share Posted March 3, 2006 [!--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? Quote Link to comment Share on other sites More sharing options...
Prank Posted March 4, 2006 Author Share Posted March 4, 2006 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 Quote Link to comment Share on other sites More sharing options...
Kingskin Posted March 4, 2006 Share Posted March 4, 2006 Well, you have this line:$start = $screen * $rows_per_page;before you have defined the value of $rows_per_pagedont know if thats the problem but it just jumped out at me. Quote Link to comment Share on other sites More sharing options...
wickning1 Posted March 4, 2006 Share Posted March 4, 2006 Yes, that's exactly the problem, you're multiplying by $rows_per_page before you've set it to 30! Quote Link to comment Share on other sites More sharing options...
Prank Posted March 6, 2006 Author Share Posted March 6, 2006 Love your work guys! Thanks very much!Christian Quote Link to comment Share on other sites More sharing options...
XenoPhage Posted March 6, 2006 Share Posted March 6, 2006 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 Link to comment Share on other sites More sharing options...
Prank Posted March 7, 2006 Author Share Posted March 7, 2006 [!--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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.