php/mysql newbie question
excuse the title but as im not an expericened programmer i dont know how to describe this problem
So the problem. I have 2 topics in my topics table. When im on thread 2 it correclty prints a thread to thread 1 but when im on thread 1 it doesnt print the link to thread 2.
Whats wrong?
$prev_thread = mysql_query("SELECT MAX(id) as prev_thread_id
FROM topics
WHERE id < $threadid
AND boardid = 1");
$next_thread = mysql_query("SELECT MIN(id) as next_thread_id
FROM topics
WHERE id > $threadid
AND boardid = 1");
$prev = mysql_fetch_assoc($prev_thread);
$next = mysql_fetch_assoc($next_thread);
?>
<?php if ($prev['prev_thread_id']): ?&g开发者_运维问答t;
<b><a href="<?=URL?>/forum/?action=thread&threadid=<?php echo $prev['prev_thread_id']?>">< Previous Topic</a> </b>
<?php endif ?>
<?php if ($next['next_thread_id']): ?>
<b><a href="<?=URL?>/forum/?action=thread&threadid=<?php echo $next['next_thread_id']?>">Next Topic ></a></b>
<?php endif ?>
I think its the "<" you have before "Previous Topic". Change that to a <
I see no reason why the following shouldn't work:
<?php
$prev_thread = mysql_query("SELECT MAX(id) as prev_thread_id
FROM topics
WHERE id < $threadid
AND boardid = 1 LIMIT 1");
$next_thread = mysql_query("SELECT MIN(id) as next_thread_id
FROM topics
WHERE id > $threadid
AND boardid = 1 LIMIT 1");
$prev = mysql_fetch_assoc($prev_thread);
$next = mysql_fetch_assoc($next_thread);
?>
<?php if ($prev['prev_thread_id']): ?>
<b><a href="<?=URL?>/forum/?action=thread&threadid=<?php echo $prev['prev_thread_id']?>">< Previous Topic</a> </b>
<?php endif; ?>
<?php if ($next['next_thread_id']): ?>
<b><a href="<?=URL?>/forum/?action=thread&threadid=<?php echo $next['next_thread_id']?>">Next Topic ></a></b>
<?php endif; ?>
Try it.
精彩评论