tags:

views:

42

answers:

1

Hiho!

I need some help.

I use this SQL to check for previous / next threads.

$prev=SELECT MAX(id) as prev_thread_id
FROM threads
WHERE id < $threadid
AND forumid = $forumid

$next=SELECT MIN(id) as next_thread_id
FROM threads
WHERE id > $threadid
AND forumid = $forumid

How would I do to check if theres a previous thread and then print a link "Previous Thread" is there are. Same with next.

I tired mysql_num_row($next) == 0 but dont work

Some help would be nice

Thank you

+1  A: 

MIN/MAX will always return exactly 1 row containing requested number or NULL. So just parse the result of a query and see what is returned in its first row.

serg
In more detail, they'll return the minimum and maximum IDs that match your WHERE clause. As such, they will always return *1* row, the content of which will be the min/max ID, or null.
Marc B