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

  • Home
  • SEARCH
  • 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 8881345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:19:43+00:00 2026-06-14T20:19:43+00:00

I am trying to get an array of values from one mysql table then

  • 0

I am trying to get an array of values from one mysql table then search through another table for those values and pull data from them. Imagine two tables: an orders table (id, product_id) and a products table (id, price). I’m basically trying to use an array full of orders.id to sum products.price of those ids in the array.

I’ve figured out how to get the array full of orders.id in PHP using

    $results = mysql_query("SELECT id FROM orders WHERE some_value =" . $passed_value . "");
    while ($row = mysql_fetch_row($results))
      {
        $results_array[] = $row[0]; 
      }

So the question is, now that I have that array, how do I use it to search another table for any id in the array and then pull data from that row.

  • 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-14T20:19:44+00:00Added an answer on June 14, 2026 at 8:19 pm

    You can use the $results_array to get the product ID, and then do another query like the one you did using $results_array['product_id'].

    However, this is very inefficient. The proper way is to do an SQL join or a simple joint query like this:

    SELECT orders.id, orders.product_id, products.price 
    FROM orders, products 
    WHERE orders.id = '" . $your_order_id . "' and products.id = orders.product_id
    

    The resultant rows will have all the information you need from both tables.

    UPDATE: More information

    When using the Where clause to join implicitly, it is effectively an Inner Join. I.e it returns rows when there is at least one match in both tables. A left join on the other hand returns all rows from the first table, even if there are no matching rows in the second table (in which case you get the respective fields corresponding to the second table null).

    So rather than performance (which is more determined by the indexes you have on your fields, although the type of join might have some impact), what you choose depends on what results you want to get. You might want to look here (make sure you read the 5 consecutive pages about joins) to get a full understanding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the values from a pointer to a float array, but
I'm trying to get one object from this array and print all of its
i'm trying to sum up values from one record (A) then add it to
I am trying to get multiple rows to insert into a mysql table from
Update mysql with $_POST data from while loop I'm trying to get this round
I'm trying to get a specific value from a mysql_fletch_assoc array. I explain. Here
I am trying to store values in array using JavaScript, but I get strange
I'm trying to get a table form a numpy array at the barplot bottom
I'm trying to get from an Android Uri to a byte array. I have
I am trying to query an SQL table, and then have all the values

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.