Jump to content

Automated most recent/newest list?


Sparrow

Recommended Posts

So far I have a table of my sites members that automatically updates itself whenever a new member registers.  Now I am wondering is there a way to limit this table to displaying only the newest members?  The reason why I am asking is because I would like to display a small table on the hompage of my website that says: "Please welcome our newest members"         

 

Also I have another question.  For each member I have some statistics (flight hours, ect) that are automatically updated.  Now I am wondering is there a way to add all theses statistics so that I can display an overall stats page on my home page (e.g.  Total Flight Hours) 

 

A good example of what I am asking for can be found on the right side of this website:  http://www.vcair.com/

 

Thank you for help

Link to comment
https://forums.phpfreaks.com/topic/117203-automated-most-recentnewest-list/
Share on other sites

Do you store the date they sign up, or do you have any other way of ordering them by their signup (auto_increment field or anything)? If so, just do something like this:

SELECT * FROM members ORDER BY sort_field DESC LIMIT 10;

 

That will grab your latest 10 members based on your sort_field (whatever that may be).

Sorry I'm not really that expert with PHP so were would I insert that.  BTW my members table can be found here:  http://www.unitedairlinesva.com/VirtualAdminII2.0/roster.php (Website is temporary) 

 

And here is the coding for that table: 

 

<?


$result = mysql_query("select * from users");
$num = mysql_num_rows($result);
$i = 0;
?>

<table cellpadding="4" cellspacing="3" align="center" style=" border: solid #000000 1px" width="100%">

    <tr bgcolor="#b5d0e5" style="color: #997711">
<th bgcolor="#CC0000"><font color="#FFFFFF">Pilot ID</font></th>
<th bgcolor="#CC0000"><font color="#FFFFFF">Rank</font></th>
<th bgcolor="#CC0000"><font color="#FFFFFF">Pilot Name</font></th>
<th bgcolor="#CC0000"><font color="#FFFFFF">VATSIM ID</font></th>
    <th bgcolor="#CC0000"><font color="#FFFFFF">Flight Hours</font></th>
<th bgcolor="#CC0000"><font color="#FFFFFF">Location</font></th>
<th bgcolor="#CC0000"><font color="#FFFFFF">Entered Service</font></th>
    </tr>
<?

while($i < $num) {

        

$ghours = mysql_query("select * from users");
$hourcount = mysql_num_rows($ghours);
$a = 0;
$hourstrue = 0;
$hours = 0.0;



  $c_h = mysql_result($result,$i,"flthrs");

  $hours += $c_h;

if($hours <= 50.00):
        {
        $rank = "First Officer";
        }
        elseif($hours > 51.00 AND $hours <= 100.00):
        {
        $rank = "Second Officer";
        }
        elseif($hours > 101.00 AND $hours <= 200.00):
        {
        $rank = "Captain";
        }
        elseif($hours > 201.00 AND $hours <= 350.00):
        {
        $rank = "Senior Captain";
        }
  elseif($hours > 351.00 AND $hours <= 500.00):
        {
        $rank = "Master Senior Captain";
        }
        elseif($hours > 501.00):
        {
        $rank = "Command Senior Captain";
        }
else:
        {
        $rank = "First Officer";
        } 
endif;

$username = mysql_result($result,$i,"username");
$name = mysql_result($result,$i,"name");
        $VATSIM_ID = mysql_result($result,$i,"VATSIM_ID");
        $FPI_ID = mysql_result($result,$i,"FPI_ID");
$flthrs = mysql_result($result,$i,"flthrs");
$location = mysql_result($result,$i,"location");
$signup_date = mysql_result($result,$i,"signup_date");
?>
    <tr style="color: #997711">
<td align="center"><?echo $username;?></td>
<td align="center"><?echo $rank;?></td>
<td align="center"><?echo $name;?></td>
<td align="center"><?echo $VATSIM_ID;?></td>
<td align="center"><?echo $flthrs;?></td>
<td align="center"><?echo $location;?></td>
<td align="center"><?echo $signup_date;?></td>
    </tr>
<? 
$i++;} 
?>
</table>
<table align="center">

 

Also if you have noticed I have a pilot rank system set up based on flight hours.  I would also like to set-up a pay system based on flight hours (e.g. 50/h). How would I do that?

Do you store the date they sign up, or do you have any other way of ordering them by their signup (auto_increment field or anything)? If so, just do something like this:

SELECT * FROM members ORDER BY sort_field DESC LIMIT 10;

 

That will grab your latest 10 members based on your sort_field (whatever that may be).

 

Where would I insert that code?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.