2010-07-14 93 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; ?> 

試試吧。