Finney Posted April 8, 2007 Share Posted April 8, 2007 Hey, I am currently working on a project in php and Im stuck on a part so I thought Id come to the most popular php help forum for fast good realiable help.. I have got myself a memberlist, I got it to show the rows I need, and I only want it to show 25 members on the page, which I have done. I am just confused how I make it to say like ''<< Back'' and ''Next >>'' to view the last or next 25 members from the table. What I am asking for is for somebody to help me with a peice of code to help achieve this.. Future thanks for help given. Quote Link to comment https://forums.phpfreaks.com/topic/46132-php-listing/ Share on other sites More sharing options...
MadTechie Posted April 8, 2007 Share Posted April 8, 2007 for MySQL use Limit SELECT * FROM `your_table` LIMIT 0, 25 shows first 25 SELECT * FROM `your_table` LIMIT 25, 25 next 25 SELECT * FROM `your_table` LIMIT 50, 25 next 25 SELECT * FROM `your_table` LIMIT 75, 25 etc etc etc Quote Link to comment https://forums.phpfreaks.com/topic/46132-php-listing/#findComment-224200 Share on other sites More sharing options...
Finney Posted April 8, 2007 Author Share Posted April 8, 2007 Ok, I understand that but how do I make it so its got pages to show..? Quote Link to comment https://forums.phpfreaks.com/topic/46132-php-listing/#findComment-224402 Share on other sites More sharing options...
MadTechie Posted April 9, 2007 Share Posted April 9, 2007 just say total records is 2780 and items per page is 25 thats 2780 / 25 =111.2 (112 rounded up) so 112 pages in total if you click on page 50 that would be 50*25 =1250 the SQL statement would be SELECT * FROM `your_table` LIMIT 1250, 25 if you have some code it would help if not then write a simple one to list all and then try adding the logic above and post your results Quote Link to comment https://forums.phpfreaks.com/topic/46132-php-listing/#findComment-224608 Share on other sites More sharing options...
Finney Posted April 9, 2007 Author Share Posted April 9, 2007 Ok, Ill show you some code.. <?php $title = "<u>Memberlist</u>"; include("header.php"); ?> <?php print "<center>"; print "<table>"; print "<tr><td width=80><center><b><u>Name</td><td width=50><center><b><u>Level</td><td width=50><center><b><u>Cash</td><td width=130><center><b><u>Gang</td><td width=50><center><b><u>Status</td></tr>"; $msel = mysql_query("select * from players where varified='Yes' order by user asc limit 0 , 25"); while ($mem = mysql_fetch_array($msel)) { print "<tr><td><A href=profile.php?view=$mem[id]>$mem[user]</a><td><center>$mem[level]</td><td>"; print "$".number_format($mem[cash]); print "</td><td><center><a href=gangs.php?view=view&id=$mem[gang]>$mem[tag]</a></td><td><center> [ Offline ]</td></tr>"; } print "</table>"; print "<br>"; include("footer.php"); ?> There, it shows what I want but I want to be able to go through pages.. If you understand me? Quote Link to comment https://forums.phpfreaks.com/topic/46132-php-listing/#findComment-224860 Share on other sites More sharing options...
clown[NOR] Posted April 9, 2007 Share Posted April 9, 2007 i have no experience with mysql at all, when that's said.. what sounds most logical to me is making something like ?view=members&id=1 ?view=members&id=2 the in the members.php file have a code that sais if id is equal to 1, then show 1-25, if equal to 2, then show 26-50 and so on Quote Link to comment https://forums.phpfreaks.com/topic/46132-php-listing/#findComment-224863 Share on other sites More sharing options...
Finney Posted April 9, 2007 Author Share Posted April 9, 2007 Yeah that was the idea I was looking for, but I was stuck in need of a bit of code to help me with.. Quote Link to comment https://forums.phpfreaks.com/topic/46132-php-listing/#findComment-224864 Share on other sites More sharing options...
jitesh Posted April 9, 2007 Share Posted April 9, 2007 Use Search Keywods : paging at http://www.phpclasses.org Quote Link to comment https://forums.phpfreaks.com/topic/46132-php-listing/#findComment-224879 Share on other sites More sharing options...
MadTechie Posted April 9, 2007 Share Posted April 9, 2007 this will work like file.php?page=1 file.php?page=2 file.php?page=3 <?php $page = $_GET['page']; //<---added $display = 25; $start = $display*($page - 1); $end = $display*$page; ?> <?php $title = "<u>Memberlist</u>"; include("header.php"); ?> <?php print "<center>"; print "<table>"; print "<tr><td width=80><center><b><u>Name</td><td width=50><center><b><u>Level</td><td width=50><center><b><u>Cash</td><td width=130><center><b><u>Gang</td><td width=50><center><b><u>Status</td></tr>"; //updated $msel = mysql_query("select * from players where varified='Yes' order by user asc limit $start, $end"); while ($mem = mysql_fetch_array($msel)) { print "<tr><td><A href=profile.php?view=$mem[id]>$mem[user]</a><td><center>$mem[level]</td><td>"; print "$".number_format($mem[cash]); print "</td><td><center><a href=gangs.php?view=view&id=$mem[gang]>$mem[tag]</a></td><td><center> [ Offline ]</td></tr>"; } print "</table>"; print "<br>"; include("footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/46132-php-listing/#findComment-224941 Share on other sites More sharing options...
Finney Posted April 10, 2007 Author Share Posted April 10, 2007 Mmm, I get an SQL error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /memberlist.php on line 17 But I have checked all the SQL, heres the code again: <?php $title = "<u>Memberlist</u>"; include("header.php"); ?> <?php print "<center>"; print "<table>"; print "<tr><td width=80><center><b><u>Name</td><td width=50><center><b><u>Level</td><td width=50><center><b><u>Cash</td><td width=130><center><b><u>Gang</td><td width=50><center><b><u>Status</td></tr>"; $msel = mysql_query("select * from players where varified='Yes' order by user asc limit 0 , 25"); while ($mem = mysql_fetch_array($msel)) { print "<tr><td><A href=profile.php?view=$mem[id]>$mem[user]</a><td><center>$mem[level]</td><td>"; print "$".number_format($mem[gold]); print "</td><td><center><a href=gangs.php?view=view&id=$mem[clan]>$mem[tag]</a></td><td><center> [ Offline ]</td></tr>"; } print "</table>"; print "<br>"; include("footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/46132-php-listing/#findComment-225848 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.