There's a number of ways. Starting with this, which is the root of your question,
need this because i want to select the last 4 rows in my database
First, get your select out of the command and into a variable. :-) This will make it much easier to experiment with and debug.
Second, you say "last four" but what's last four? Assuming your first column is auto-increment, it should be fairly reliable to use order by the auto increment column, and limit 4 to get the last four, but there are a couple conditions by which it many not actually be the last four (sorry, I forget what those conditions are . . . . ) It may be to your advantage to add a datetime field and order by that field instead, as that field will have other important uses (like, who signed up today . . . )
Assuming the first column is named "id" (as is too often the case, to the advantage of hackers,)
$how_many=4;
$direction='desc';
$query = "select name, email from users order by id $direction limit $how_many";
$users = $db->get_results($query);
... should do the trick. I put the direction and number of rows in variables because this is how you will probably eventually need them - as in, selectable from a search form. Even if not, at the top of the script in an easy to locate config section.
A little more info on this, so you know what's happening:
Now $users contains the results.
Not exactly. :-) What you need to do is command one of the row functions, mysql_fetch_assoc or mysql fetch_array, and judging by your code, it looks like you are using a connection class I've seen. So an easier approach might be something like this:
$how_many=4;
$direction='desc';
//
$query = "select name, email from users order by id $direction limit $how_many";
//
$result = $db->query($query);
while ($row=$db->fetch_array($result)) {
// you can use ASSOCIATIVE or INDEXED
// queries here. Displaying both.
echo "<p>Associative: " . $row['name'] . " " . $row['email'] . "</p>\n";
echo "<p>Indexed: " . $row[0] . " " . $row[1] . "</p>\n";
}
If you had done select *, 0 (zero) would be id, 1 would be name, 2 would be email.