monkeypaw201 Posted January 15, 2010 Share Posted January 15, 2010 If I were to have a database with 20 columns, and wanted to query it and have an associative array called `table` automatically have all of the database columns added to it, how would I do that? Meaning, later on in the script, I could call a specific value (each query is LIMIT 1) echo $table['column3']; Quote Link to comment https://forums.phpfreaks.com/topic/188576-automatically-generating-arrays-based-on-database-columns/ Share on other sites More sharing options...
calmchess Posted January 15, 2010 Share Posted January 15, 2010 while($row = mysql_fetch_row($result){ array_push(table,$row[0]); } Quote Link to comment https://forums.phpfreaks.com/topic/188576-automatically-generating-arrays-based-on-database-columns/#findComment-995591 Share on other sites More sharing options...
Buddski Posted January 15, 2010 Share Posted January 15, 2010 If your calling query limit is 1 $table = mysql_fetch_assoc($sql_query); will be fine calmchess' method will only add the value of $row[0] into the array and not all the fields in the database.. Quote Link to comment https://forums.phpfreaks.com/topic/188576-automatically-generating-arrays-based-on-database-columns/#findComment-995595 Share on other sites More sharing options...
calmchess Posted January 15, 2010 Share Posted January 15, 2010 I've gotta read things more carefully.....sorry about the bad post. Quote Link to comment https://forums.phpfreaks.com/topic/188576-automatically-generating-arrays-based-on-database-columns/#findComment-995606 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.