ianco Posted April 9, 2012 Share Posted April 9, 2012 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 More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 Learn to use JOINS Link to comment https://forums.phpfreaks.com/topic/260612-generating-an-array-from-mysql-table/#findComment-1335639 Share on other sites More sharing options...
ianco Posted April 9, 2012 Author Share Posted April 9, 2012 I'm not sure JOINS will work because the cell could contain e.g. "2,5,19,21" so i can have $range = "2,5,19,21"; but I want to change that into an array $arr = array($range); Link to comment https://forums.phpfreaks.com/topic/260612-generating-an-array-from-mysql-table/#findComment-1335681 Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 $range = $rowShowIng['keyno']; $arr = explode(',', $range); print_r($arr); Link to comment https://forums.phpfreaks.com/topic/260612-generating-an-array-from-mysql-table/#findComment-1335684 Share on other sites More sharing options...
ianco Posted April 9, 2012 Author Share Posted April 9, 2012 bingo, cheers Link to comment https://forums.phpfreaks.com/topic/260612-generating-an-array-from-mysql-table/#findComment-1335697 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.