Jump to content

generating an array from mysql table


ianco

Recommended Posts

Hi all,

 

I want to create an array from the output of a table. In the table cell I have some numbers where for each number I would like to relate it to a value in another table. However using the code below I get Array ( [0] => "26","27","28","29","30","31" ) from the print_r($arr); meaning that $range ins't being treated as an array, and hence, the second query only gives one value.

 

$showIng = mysql_query("SELECT * FROM recipe WHERE name = '$dish'") or die(mysql_error());

$rowShowIng = mysql_fetch_assoc($showIng);

$range = $rowShowIng['keyno'];

$arr = array($range);
print_r($arr);

foreach ($arr as &$value) {
$getIng = mysql_query("SELECT * FROM keywords WHERE keyid = '$value'") or die(mysql_error());
$rowGetIng = mysql_fetch_assoc($getIng);
echo $rowGetIng['ingredient'];
}

 

So, I want to know how I can create the array from $range

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.