954,176 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Automatic Pages from While Loop

Hello everyone.

I currently have a while loop that pulls all members to a page if the username begins with the selected letter. We have a lot of members now and the "usernames beginning with "a" are quite alot. So i need to be able to have a way to LIMIT to about 20 usernames then add a "new page" at the bottom. e.g i want like this at the bottom:

Page: 1 - 2 - 3 - 4 - 5 - 6, etc

And these are linked to the same page so the php code can list the next 20 members...

Here is my code at the minute and thank you very much in advance:

<?php
$letter = $_GET['sort'];
if(!isset($letter)) {
$letter = "a";
}
$lettercombo = "$letter%";
$select = mysql_query("SELECT * FROM users WHERE username LIKE '$lettercombo' ORDER by username");
while($fetch = mysql_fetch_array($select)) {
?>
  
  <tr>
   <td><a style="color:#5b9600; font-weight:bold; text-shadow:0px 1px 0px #fff;" href="viewuser.php?user=<? echo $fetch['username']; ?>"><? echo $fetch['username']; ?></a></td>
   <td><? echo $fetch['gamertag']; ?></td>
   <td><? echo $fetch['joined']; ?></td>
  </tr>
 
<? } ?>
BlueCharge
Light Poster
46 posts since Jan 2010
Reputation Points: 10
Solved Threads: 1
 

why dont you retrieve the contents of the while loop into an array and check if its greater than the limit 20.

anony
Newbie Poster
20 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

use queries like this
$res="mysql_query("SELECT * FROM users WHERE username LIKE '$lettercombo' ORDER by username");
$num=mysql_num_rows($res);
$limit=0;
$select = mysql_query("SELECT * FROM users WHERE username LIKE '$lettercombo' ORDER by username limit $limit-20");
while($fetch = mysql_fetch_array($select)) {

?>

<? echo $fetch['username']; ?>
<? echo $fetch['gamertag']; ?>

<? echo $fetch['joined']; ?>


<? $limit+=20} ?>

Karthik.gautham
Newbie Poster
17 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 
rajarajan07
Nearly a Posting Virtuoso
1,447 posts since May 2008
Reputation Points: 167
Solved Threads: 239
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You