开发者

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&amp;threadid=<?php echo   $prev['prev_thread_id']?>">< Previous Topic</a>&nbsp;&nbsp;&nbsp;&nbsp;</b>
<?php endif ?>

<?php if ($next['next_thread_id']): ?>
<b><a href="<?=URL?>/forum/?action=thread&amp;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 &lt;


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&amp;threadid=<?php echo $prev['prev_thread_id']?>">&lt; Previous Topic</a>&nbsp;&nbsp;&nbsp;&nbsp;</b>
<?php endif; ?>

<?php if ($next['next_thread_id']): ?>
<b><a href="<?=URL?>/forum/?action=thread&amp;threadid=<?php echo $next['next_thread_id']?>">Next Topic &gt;</a></b>
<?php endif; ?>

Try it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜