title: Use result from one query as an input into another query on MySQL
body: <p>I am trying to use a result from one query as input for another query but I am stumped.  I thought about using JOIN but I think in this case the two queries need to me run separately.  Essentially I have a list of articles in my database.  As I loop through the list or articles that I obtained from my first query I want to search a second table to find out the number of votes that each article has.  </p>
  
  <p>This is the code:</p>
  
  <pre><code>&lt;?php
    $sql=mysql_query("SELECT * FROM discussion_links WHERE link_side = 'Michigan'");
    while($row = mysql_fetch_array($sql)) {
  ?&gt;
  
  &lt;div class="top-links-wrapper"&gt;
      &lt;div&gt;
         &lt;div class="link-info"&gt;
             &lt;a class="link-title" href="http://&lt;?php echo $row['link_url'] ?&gt;"&gt;
             &lt;?php echo $row['link_title'] . "&lt;/a&gt;"; ?&gt;
             &lt;p class="link-source"&gt;&lt;?php echo $row['link_source'] . "&lt;/p&gt;" ?&gt;
         &lt;/div&gt;
         &lt;div class="link-vote-wrapper"&gt;
             &lt;span class="link-votes"&gt;
             &lt;?php    
                  $sql2=mysql_query("SELECT * FROM link_votes WHERE link_id = " . $row['link_id'] .")";
                  $num_rows = mysql_num_rows($sql2);
                  echo "$num_rows";
              ?&gt;
             &lt;/span&gt;
         &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Thanks</p>