+----+
| id |
+----+
| 1 |
+----+
| 2 |
+----+
| 3 |
+----+
| 4 |
+----+
+----+
| 5 |
+----+
How do I show records from a specific ID so the list would show 2,3,4,5 or 3,4,5?
I figured to do with two queries in UNION but end up showing 2,1,3,4,5 or 2,5,4,3,1.
Did you mean
SELECT * FROM table WHERE id IN (2,3,4,5)
SELECT * FROM table WHERE id >= $id ORDER BY id ASC LIMIT 4
In the second query $id is the input from the user. Also instead of LIMIT 4, you can have the 4 taken as user input
Maybe
$sql = "SELECT * FROM table WHERE id >= $curID ORDER BY id ASC LIMIT 4";
If you want to specify how many entries to find, you can use:
$sql = "SELECT * FROM table WHERE id >= $curID ORDER BY id ASC LIMIT $number";
Be sure you sanitize the inputs before plugging them into the query. See this post for more info: What's the best method for sanitizing user input with PHP?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.