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.

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...

$query = "SELECT * FROM tbl_accounts ORDER BY userID DESC LIMIT 4";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.