Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing array values in mysql Where
    primarykey
    data
    text
    <p>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. </p> <pre><code>$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 =&gt; $value) { $i++; // increment $i by one each loop pass echo "Cart Item $i ______ key = $key | value = $value&lt;br /&gt;"; } $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 =&gt; $v) { $ii++; // increment $i by one each loop pass print_r ($v); } ?&gt; </code></pre> <p>outputs </p> <pre><code>Cart Item 1 ______ key = restaurant_id | value = 10 Cart Item 2 ______ key = restaurant_id | value = 14 // the phone_number 444444444 </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload