How can i display only the last 4 rows from the DataBase?
This is my code:
$sql3 = "SELECT *
FROM `event_guests`
WHERE `idevent`='".$idevent."'
ORDER BY `id` ASC
LIMIT 4";
Note that i don't want to use DESC to order them in reverse because i want the last row to be the last row and not the first. Alse just display 4 rows even if there is more.
It sounds like you want two order bys:
SELECT eg.*
FROM (SELECT eg.*
FROM event_guests eg
WHERE eg.idevent = ?
ORDER BY eg.id DESC
LIMIT 4
) eg
ORDER BY id ASC;
The ?
is for a parameter placeholder. You should learn how to use them rather than munging query strings with parameters. What you are doing is very dangerous (makes the code subject to SQL injection attacks) and can affect the performance of queries.