Jump to content

Recommended Posts

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.  :)

Link to comment
https://forums.phpfreaks.com/topic/46132-php-listing/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/46132-php-listing/#findComment-224608
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/46132-php-listing/#findComment-224860
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/46132-php-listing/#findComment-224863
Share on other sites

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");
?>

Link to comment
https://forums.phpfreaks.com/topic/46132-php-listing/#findComment-224941
Share on other sites

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");
?>

Link to comment
https://forums.phpfreaks.com/topic/46132-php-listing/#findComment-225848
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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