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 8769037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:13:43+00:00 2026-06-13T17:13:43+00:00

I have multiple MYSQL SELECT querys feed in each other, the first one selects

  • 0

I have multiple MYSQL SELECT querys feed in each other, the first one selects the row id, puts them in an array, The second SELECT query needs to use those values 10,14 etc, to acess the rest of the restaurants info in other tables, the problem im having is the second query is only selecting the last phone_number based on the last value in the array 14.

$city= 'london';
$cuisine ='indian';


$sql=(" SELECT restaurant_id FROM restaurants WHERE  city = '$city' AND cuisine=                     '$cuisine'  ");

mysql_select_db('RESTAURANTS');
$retval = mysql_query( $sql, $conn ); 
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))


foreach ($row as $key => $value) { 
$i++; // increment $i by one each loop pass 

echo "Cart Item $i ______ key = $key | value = $value<br />"; }





$sql1 = "SELECT phone_number FROM restaurants WHERE  ($key) IN ($value)";



mysql_select_db('RESTAURANTS');
$retval1 = mysql_query( $sql1, $conn ); 
if(! $retval1 )
{
die('Could not get data: ' . mysql_error());
}
while($row1 = mysql_fetch_array($retval1, MYSQL_ASSOC))


foreach ($row1 as $k => $v) { 
$ii++; // increment $i by one each loop pass 
         print_r ($v);


}
?> 

outputs

Cart Item 1 ______ key = restaurant_id | value = 10
Cart Item 2 ______ key = restaurant_id | value = 14

// the phone_number
444444444

Only selects the phone_number of 14 not 10 also why? do I need some sort of extra function to loop through the array again, iv’e tried implode and mysql_value functions, iv’e tried everything I can think off, any help appreciated.

  • 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-13T17:13:44+00:00Added an answer on June 13, 2026 at 5:13 pm

    Your code is attrociously formatted. Had you used proper indenting, you’d see that your first while() loop is malformed:

    while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
                                                          ^--- no {
        foreach ($row as $key => $value) { 
        $i++; // increment $i by one each loop pass 
    
        echo "Cart Item $i ______ key = $key | value = $value<br />"; }
    

    As such, it will retrieve all the rows of that first query and output the individual fields. But since you didn’t use proper bracketing, the next chunk of code (your next sql query/loop) is NOT part of this first while loop, so you only execute that phone number fetching query ONCE.

    It should be

     while(... first query) {
          print values
          do inner query
          while (fetch inner query) {
               print values
          }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Can I concatenate multiple MySQL rows into one field? I have three
Is it possible to select one row in MySQL and then miss 4 rows
Possible Duplicate: MySQL Select Multiple VALUES lets say i have a group of number
I have an array being collect via a form like below: <select multiple=multiple name=contractors[]
I have multiple tables in a MySQL database. Lets say they look like this:
I have multiple columns in a mySQL table. Three of the columns are named
I have multiple tables in a mysql database and I am trying to put
I have multiple lines of text entered into a single MySQL longtext cell that
I will have multiple tables used by different projects on the same mySql server.
Basically, I have multiple URL's stored in a MySQL table. I want to pull

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.