2017-02-21 30 views
1

これから始めるつもりですが、これは先進的な行動であろうとなかろうと、私にとって初めてのものです。大した言葉は、私は理解していない、私は基本を知っていると私はそれが笑それについて達成しようとしていることを知っている。なぜ結果が重複して返されますか?

私は今これをしばらくプレイしていますが、私はうまく動作するように管理していますが、今は重複した結果が得られています。

は、ここに私のコードです:

<?php 
$addonid = $db->query_read(" 
     SELECT drc.threadid AS threadid 
     FROM `" . TABLE_PREFIX . "modsys_settings` AS drc 
     LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread 
     ON(drc.mod_addons=" . $threadinfo['threadid'] . ") 
     WHERE thread.threadid IN (" . $threadinfo['threadid'] . ") 
    "); 
while ($addons = $db->fetch_array($addonid)) { 
    $ci_counter = $db->query_read(" 
      SELECT drc.mod_addons AS addon, drc.threadid, thread.threadid AS threadid, thread.title AS threadtitle 
      FROM `" . TABLE_PREFIX . "modsys_settings` AS drc 
      LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread ON(drc.mod_addons=" . $threadinfo['threadid'] . ") 
      WHERE thread.threadid IN (" . $addons['threadid'] . ") 
     "); 

    while ($counter = $db->fetch_array($ci_counter)) { 
     $post['addons'] .= '<li><a href="showthread.php?t=' . $addons['threadid'] . '">' . $counter['threadtitle'] . '</a></li>'; 
    } 
} 
?> 

一体その混乱は何!?まあ、それは私が笑に働くことができたものなので、それは何ですか?簡単に言えば、ある列にthreadidを探し、別の表の列にその表のタイトル列をつかむ場合です。次に、値の変数を使用して、それぞれのリストリンクを作成します。それは実際に働いたとき私に衝撃を与えた、そして私がここにいるものではないが、私がそれを改善する方法を私に教えてくれました。問題がある

、それはすべてのダブルを返すので、代わりに私が

<li><a href="showthread.php?t=4">result</a></li> 
<li><a href="showthread.php?t=4">result</a></li> 
<li><a href="showthread.php?t=5">result 2</a></li> 
<li><a href="showthread.php?t=5">result 2</a></li> 

これはなぜ

を取得しています

<li><a href="showthread.php?t=4">result</a></li> 
<li><a href="showthread.php?t=5">result 2</a></li> 

を取得するのですか?それを解決するために私は何ができますか?

私は戻っているループからクエリを削除したが、今では

<?php 
$addonid = $db->query_read(" 
     SELECT drc.threadid AS threadid 
     FROM `" . TABLE_PREFIX . "modsys_settings` AS drc 
     LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread 
     ON(drc.mod_addons=" . $threadinfo['threadid'] . ") 
     WHERE thread.threadid IN (" . $threadinfo['threadid'] . ") 
    "); 
$addons = $db->fetch_array($addonid); 
$ci_counter = $db->query_read(" 
      SELECT drc.mod_addons AS addon, drc.threadid, thread.threadid AS threadid, thread.title AS threadtitle 
      FROM `" . TABLE_PREFIX . "modsys_settings` AS drc 
      LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread ON(drc.mod_addons=" . $threadinfo['threadid'] . ") 
      WHERE thread.threadid IN (" . $addons['threadid'] . ") 
     "); 

while ($counter = $db->fetch_array($ci_counter)) { 
    $post['addons'] .= '<li><a href="showthread.php?t=' . $addons['threadid'] . '">' . $counter['threadtitle'] . '</a></li>'; 
} 
?> 

(4である)検出された最初の列の唯一の復帰重複しています

<li><a href="showthread.php?t=4">result</a></li> 
<li><a href="showthread.php?t=4">result</a></li> 
+1

あなたは」 whileループでクエリを実行しているので重複を取得しています。 –

+0

私は下部の編集でOPを更新しました –

答えて

2
$addonid = $db->query_read (" 
     SELECT drc.threadid AS threadid 
     FROM `" . TABLE_PREFIX . "modsys_settings` AS drc 
     LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread 
     ON(drc.mod_addons=" . $threadinfo['threadid'] . ") 
     WHERE thread.threadid IN (" . $threadinfo['threadid'] . ") 
    "); 
    while ($addons = $db->fetch_array ($addonid)) {  
     $ci_counter = $db->query_read (" 
      SELECT drc.mod_addons AS addon, drc.threadid, thread.threadid AS threadid, thread.title AS threadtitle 
      FROM `" . TABLE_PREFIX . "modsys_settings` AS drc 
      LEFT JOIN `" . TABLE_PREFIX . "thread` AS thread ON(drc.mod_addons=" . $threadinfo['threadid'] . ") 
      WHERE thread.threadid IN (" . $addons['threadid'] . ") 
     "); 

     $counter = $db->fetch_array ($ci_counter); 
     if($counter != ''){ 
     $post['addons'] .= '<li><a href="showthread.php?t=' .$addons['threadid'] . '">'. $counter['threadtitle'] .'</a></li>'; 
     } 

    } 
+0

は行方不明を修正しました。それは魅力のように働いた=) –

+0

はい、それはあなたのために働いていますか? –

+0

完璧に、ありがとうございました。私はそれを持っていた方法と比較して、私は将来について理解していると思う=) –

関連する問題