943,020 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 82
  • PHP RSS
Aug 13th, 2010
0

Automatic Pages from While Loop

Expand Post »
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 Syntax (Toggle Plain Text)
  1.  
  2. <?php
  3. $letter = $_GET['sort'];
  4. if(!isset($letter)) {
  5. $letter = "a";
  6. }
  7. $lettercombo = "$letter%";
  8. $select = mysql_query("SELECT * FROM users WHERE username LIKE '$lettercombo' ORDER by username");
  9. while($fetch = mysql_fetch_array($select)) {
  10. ?>
  11.  
  12. <tr>
  13. <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>
  14. <td><? echo $fetch['gamertag']; ?></td>
  15. <td><? echo $fetch['joined']; ?></td>
  16. </tr>
  17.  
  18. <? } ?>
Last edited by BlueCharge; Aug 13th, 2010 at 8:07 am.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
BlueCharge is offline Offline
42 posts
since Jan 2010
Aug 13th, 2010
0
Re: Automatic Pages from While Loop
why dont you retrieve the contents of the while loop into an array and check if its greater than the limit 20.
Last edited by anony; Aug 13th, 2010 at 9:21 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
anony is offline Offline
20 posts
since Jun 2010
Aug 13th, 2010
0
Re: Automatic Pages from While Loop
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['username']; ?>"><? echo $fetch['username']; ?></a></td>
<td><? echo $fetch['gamertag']; ?></td>

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

</tr>


<? $limit+=20} ?>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Karthik.gautham is offline Offline
17 posts
since Aug 2010
Aug 13th, 2010
0
Re: Automatic Pages from While Loop
Reputation Points: 167
Solved Threads: 239
Nearly a Posting Virtuoso
rajarajan07 is offline Offline
1,445 posts
since May 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Need Help Travelling up a Relational Tree
Next Thread in PHP Forum Timeline: explode url and explode array.......





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC