Page 1 of 1

Displaying recently joined members

Posted: Mon Dec 05, 2011 9:20 am
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 !

Re: Displaying recently joined members

Posted: Mon Dec 05, 2011 10:06 am
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'];

Re: Displaying recently joined members

Posted: Mon Dec 05, 2011 10:17 am
by Live24x7
@ Celauran,

thanks it worked the way i wanted.

This forum rocks !!