2010-07-14 52 views
1

借口冠军,但作为我不是一个程序员expericened我不知道如何来形容这个问题PHP/MySQL的新手问题

所以问题。 我在我的主题表中有2个主题。当我在线程2时它correclty打印一个线程到线程1,但是当线程1时它不打印链接到线程2.

什么错误?

$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']): ?> 
<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 ?> 
+0

它回显线程ID吗?链接是否无效?或者根本没有链接显示? – Matthew 2010-07-14 04:58:00

+0

这些是不一样的:><上一个主题 - 和 - >下一个主题>这可能是原因。看看你的标签。 – Drew 2010-07-14 05:50:11

+0

所以我发现了这个问题。我尴尬地说,但线程#2有boardid = 0 ... – Basta 2010-07-14 06:52:56

回答

3

我认为它的“<”之前有“上一个主题”。更改为&lt;

+0

而'''在下一个主题链接到'>' – BoltClock 2010-07-14 05:13:22

+0

仍然不工作 – Basta 2010-07-14 05:14:59

0

我看不出有任何理由下不应该工作:

<?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; ?> 

试试吧。