Can I somehow ignore the post with the earliest date? With SQL or PHP?
SELECT subject, date
FROM posts
WHERE id = $id
ORDER BY date DESC
while ($row = mysql_fetch_array($query)) {
Cheers
Can I somehow ignore the post with the earliest date? With SQL or PHP?
SELECT subject, date
FROM posts
WHERE id = $id
ORDER BY date DESC
while ($row = mysql_fetch_array($query)) {
Cheers
Assuming date uniquely determines a row for a given id,
SELECT subject, date
FROM posts
WHERE id = $id
AND date NOT IN
( SELECT MIN(date)
FROM posts
WHERE id = $id
)
ORDER BY date DESC
If you're using SQL 2005 or better, you could use the row_number function...
With MyCTE AS (
SELECT subject,
date,
RowNumber = ROW_NUMBER() OVER(ORDER BY date DESC)
FROM posts
WHERE id = $id)
SELECT *
FROM MyCTE
WHERE RowNumber > 1
ORDER BY date DESC
You could probably write some convoluted sql to do it, or you could just do it in your php:
$first = true;
while ($row = mysql_fetch_array($query)) {
if ( $first ) {
$first = false;
continue;
}
// Process rows here
}
I've got nothing to test this with, but would this work?
SELECT subject, date
FROM posts
WHERE id = $id
OFFSET 1
ORDER BY date DESC
Or for MySQL five compatibility as pointed out in the comments
SELECT subject, date
FROM posts
WHERE id = $id
LIMIT 1,18446744073709551615;
ORDER BY date DESC
The large number was copied exactly from the MySQL docs.