PHP Select Statement

Reply

Join Date: Jan 2008
Posts: 19
Reputation: Morty222 is an unknown quantity at this point 
Solved Threads: 0
Morty222 Morty222 is offline Offline
Newbie Poster

PHP Select Statement

 
0
  #1
Feb 1st, 2008
Any one know how I can write a php statement to call the last 4 entires from tbl_accounts by userID?

Example:

I have 4 users, userID's 1,2,3and 4. All of these users are showing on the home page. When user #5 signs up, I want user 1 to fall off home page and user 5 to take user 1 spot.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 57
Reputation: Walkere is an unknown quantity at this point 
Solved Threads: 5
Walkere Walkere is offline Offline
Junior Poster in Training

Re: PHP Select Statement

 
0
  #2
Feb 1st, 2008
Originally Posted by Morty222 View Post
Any one know how I can write a php statement to call the last 4 entires from tbl_accounts by userID?
You need to do two things here.

First, order the results in descending order, so that the latest entry is first in the list. For this, you can use "ORDER BY userID DESC".

Then, you need to grab only the first four entries (the latest four additions). For this, use "LIMIT 4".

Altogether, it should look like this...

  1. $query = "SELECT * FROM tbl_accounts ORDER BY userID DESC LIMIT 4";
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC