Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8076157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:12:16+00:00 2026-06-05T15:12:16+00:00

I am trying to use a result from one query as input for another

  • 0

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.

This is the code:

<?php
  $sql=mysql_query("SELECT * FROM discussion_links WHERE link_side = 'Michigan'");
  while($row = mysql_fetch_array($sql)) {
?>

<div class="top-links-wrapper">
    <div>
       <div class="link-info">
           <a class="link-title" href="http://<?php echo $row['link_url'] ?>">
           <?php echo $row['link_title'] . "</a>"; ?>
           <p class="link-source"><?php echo $row['link_source'] . "</p>" ?>
       </div>
       <div class="link-vote-wrapper">
           <span class="link-votes">
           <?php    
                $sql2=mysql_query("SELECT * FROM link_votes WHERE link_id = " . $row['link_id'] .")";
                $num_rows = mysql_num_rows($sql2);
                echo "$num_rows";
            ?>
           </span>
       </div>
    </div>
</div>

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:12:17+00:00Added an answer on June 5, 2026 at 3:12 pm

    You can join both queries try this

    SELECT dl.* , lv.*
    FROM discussion_links dl
    LEFT JOIN link_votes lv ON lv.link_id = dl.link_id
    WHERE link_side = 'Michigan'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the result of one query as part of a WHERE
I'm trying to use e4x to retrieve xml from the result event thrown when
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I have as a result from a dynamic query a table with only one
I'm trying to use flexigrid to show results using the values from a form.
I'm trying to retrieve images from wikimedia using the existing api, but there seems
I am trying to make one query, to get some statistic data from database.
I'm trying to search two fields as one from a MySQL database using PHP.
I am trying to use Node CSV Parser to read in a query result
I'm trying to use the result of ls in other commands (e.g. echo, rsync):

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.