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
https://forums.phpfreaks.com/topic/260612-generating-an-array-from-mysql-table/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.