title: Why am I returning duplicate results?
body: <p>I'll start off with this is all new to me, whether or not they are advanced actions, I have only pieced things together from other products and adapted to my needs.  The big terms, I don't quite understand, I know the basics and I know what I'm trying to achieve that's about it lol.</p>
  
  <p>So I've been playing with this for a while now and I've managed to get things to work, but I'm now getting duplicate results.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>&lt;?php
  $addonid = $db-&gt;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-&gt;fetch_array($addonid)) {
      $ci_counter = $db-&gt;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-&gt;fetch_array($ci_counter)) {
          $post['addons'] .= '&lt;li&gt;&lt;a href="showthread.php?t=' . $addons['threadid'] . '"&gt;' . $counter['threadtitle'] . '&lt;/a&gt;&lt;/li&gt;';
      }
  }
  ?&gt;
  </code></pre>
  
  <p>What the heck is that mess!?  Well it's what I managed to get to work lol, so what does it do?  In simple terms, it looks for the <code>threadid</code> in one column, then if its in another tables column it grabs the title column from that table.  Then it creates a list link for each of them using variables for the values. It shocked me when it actually worked, and is not what I'm here about but fell free to tell me how I can improve it lol.</p>
  
  <p>The problem is, it's returning double of everything, so instead of getting</p>
  
  <pre><code>&lt;li&gt;&lt;a href="showthread.php?t=4"&gt;result&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="showthread.php?t=5"&gt;result 2&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  
  <p>I am getting</p>
  
  <pre><code>&lt;li&gt;&lt;a href="showthread.php?t=4"&gt;result&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="showthread.php?t=4"&gt;result&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="showthread.php?t=5"&gt;result 2&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="showthread.php?t=5"&gt;result 2&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  
  <p>Why is this? What can I do to solve it?</p>
  
  <p>I have removed the query from the loop but now its only returning duplicates of the first column it finds (which is 4)</p>
  
  <pre><code>&lt;?php
  $addonid = $db-&gt;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-&gt;fetch_array($addonid);
  $ci_counter = $db-&gt;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-&gt;fetch_array($ci_counter)) {
      $post['addons'] .= '&lt;li&gt;&lt;a href="showthread.php?t=' . $addons['threadid'] . '"&gt;' . $counter['threadtitle'] . '&lt;/a&gt;&lt;/li&gt;';
  }
  ?&gt;
  </code></pre>
  
  <p>is returning:</p>
  
  <pre><code>&lt;li&gt;&lt;a href="showthread.php?t=4"&gt;result&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="showthread.php?t=4"&gt;result&lt;/a&gt;&lt;/li&gt;
  </code></pre>