Canman2005 Posted May 10, 2010 Share Posted May 10, 2010 Hi all I have the following PHP $q = mysql_query("SELECT * FROM `people` WHERE `type` = 1"); while($r = mysql_fetch_array($q)) { echo $r['product']; echo "<br>"; } This produces 1 3 6 13 which works great. But i'm trying to create an array containing those values, so I get something like array(1, 3, 6, 13) How can I achive this? I've tried $q = mysql_query("SELECT * FROM `people` WHERE `type` = 1"); while($r = mysql_fetch_array($q)) { $ray = $ray. array($r['product'].','); } but that doesn't seem to work and no matter how I tweak it, it doesn't seem to work. Can anyone help? Thanks very much Dave Quote Link to comment https://forums.phpfreaks.com/topic/201312-help-with-simple-array/ Share on other sites More sharing options...
Psycho Posted May 10, 2010 Share Posted May 10, 2010 $q = mysql_query("SELECT * FROM `people` WHERE `type`=1"); $products = array(); while($r = mysql_fetch_array($q)) { $products[] = $r['product']; } Quote Link to comment https://forums.phpfreaks.com/topic/201312-help-with-simple-array/#findComment-1056179 Share on other sites More sharing options...
Canman2005 Posted May 10, 2010 Author Share Posted May 10, 2010 thanks dude, worked a charm Quote Link to comment https://forums.phpfreaks.com/topic/201312-help-with-simple-array/#findComment-1056180 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.