Displaying recently joined members

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Live24x7
Forum Contributor
Posts: 194
Joined: Sat Nov 19, 2011 9:32 am

Displaying recently joined members

Post by Live24x7 »

I want to display a list of 5 recently joined members on a page.

I wrote this code, however it does not display the most recent members. Rather it displays 5 members sorted alphabetically.
The table 'pmember ' stores name and location amongst other details. It does not store the join time of members.
Is there a way i could display the latest members ?

Code: Select all


<?php

require_once ('connect.php');
$list=mysql_query("SELECT * FROM pmember  LIMIT 5");
while($row = mysql_fetch_array($list))
{
$recentname = $row['rname'];
$recentlocation=$row['rlocation'];
echo"<li>$recentname from $recentlocation</li>" ;

}

?>

Thanks a lot !
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Displaying recently joined members

Post by Celauran »

First, don't SELECT *, just select the column(s) you need. Second, it's not displaying the most recent because you have no ORDER BY clause.

Code: Select all

SELECT rname, rlocation FROM pmember ORDER BY join_date DESC LIMIT 5
Finally, these two lines are pointless.

Code: Select all

$recentname = $row['rname'];
$recentlocation=$row['rlocation'];
Live24x7
Forum Contributor
Posts: 194
Joined: Sat Nov 19, 2011 9:32 am

Re: Displaying recently joined members

Post by Live24x7 »

@ Celauran,

thanks it worked the way i wanted.

This forum rocks !!
Post Reply