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>
 
<? } ?>

Recommended Answers

All 3 Replies

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

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)) {

?>

<tr>
<td><a style="color:#5b9600; font-weight:bold; text-shadow:0px 1px 0px fff;" href="viewuser.php?user=<? echo $fetch; ?>"><? echo $fetch; ?></a></td>
<td><? echo $fetch; ?></td>

<td><? echo $fetch; ?></td>

</tr>


<? $limit+=20} ?>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.