wee493 Posted October 9, 2009 Share Posted October 9, 2009 I'm wanting to get table results from a database and put them in an array. I've tried using the below code which is a very poor way of doing this and it doesn't work correctly. Any ideas? $sql = mysql_query("SELECT feed_url FROM sc_feeds"); $feed = 'array('; while ($r = mysql_fetch_array($sql)){ $feed .= '"'.$r['feed_url'].'", '; } $feed .= ')'; echo $feed; Quote Link to comment https://forums.phpfreaks.com/topic/177054-put-some-table-results-in-an-array/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 9, 2009 Share Posted October 9, 2009 That's only building a string that has the syntax of a php array statement. $sql = mysql_query("SELECT feed_url FROM sc_feeds"); $feed = array(); // define an empty array while ($r = mysql_fetch_array($sql)){ $feed[] = $r['feed_url']; // add an element to the array } echo '<pre>',print_r($feed,true),'</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/177054-put-some-table-results-in-an-array/#findComment-933535 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.