MikeDXUNL Posted December 24, 2007 Share Posted December 24, 2007 alright. to get right to the point. i need results in an array.... i have tryed $result = mysql_query("SELECT * FROM table"); while($mfa = mysql_fetch_array($result)) { $array = array($mfa['field_name']); } echo $array[1]; ######################################### but that just returns the word Array i have also try to explode and implode results... it would be helpful if anyone could provide a code or helpful information Thanks, Mike Quote Link to comment https://forums.phpfreaks.com/topic/83074-putting-mysql-results-into-an-array/ Share on other sites More sharing options...
revraz Posted December 24, 2007 Share Posted December 24, 2007 $result = mysql_query("SELECT * FROM table"); while($mfa = mysql_fetch_array($result)) { print_r($mfa); } Quote Link to comment https://forums.phpfreaks.com/topic/83074-putting-mysql-results-into-an-array/#findComment-422605 Share on other sites More sharing options...
Northern Flame Posted December 24, 2007 Share Posted December 24, 2007 or trie this: <?php $result = mysql_query("SELECT * FROM table"); $x = 0; while($mfa = mysql_fetch_array($result)) { $array[$x] = $mfa['field_name']; $x++; } echo $array[1]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/83074-putting-mysql-results-into-an-array/#findComment-422607 Share on other sites More sharing options...
p2grace Posted December 24, 2007 Share Posted December 24, 2007 Also if you want the array keys to be the name of the database field use this: $query = "SELECT `var1`, `var2` ...."; $run = mysql_query($query); while($arr = mysql_fetch_assoc($run)){ extract($arr); // Takes each database field and makes it as it's own php variable echo "var = $var1, var2 = $var2 <br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/83074-putting-mysql-results-into-an-array/#findComment-422610 Share on other sites More sharing options...
MikeDXUNL Posted December 24, 2007 Author Share Posted December 24, 2007 Thanks you guys.. Northern Flame's reply was what I was looking for... along with some tweaking of my own. revraz, i didn't really get how to echo each as a seperate name.. they were all Array[0] and p2grace.. your way was nice as well.. but wasn't what i was looking for. thanks for taking the time to help Quote Link to comment https://forums.phpfreaks.com/topic/83074-putting-mysql-results-into-an-array/#findComment-422615 Share on other sites More sharing options...
p2grace Posted December 24, 2007 Share Posted December 24, 2007 Glad we were able to help. Would you mind marking the post as solved. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/83074-putting-mysql-results-into-an-array/#findComment-422616 Share on other sites More sharing options...
revraz Posted December 24, 2007 Share Posted December 24, 2007 Was just trying to show you that the mysql_fetch_array was already putting your results into an array and you didnt need to do it again. Quote Link to comment https://forums.phpfreaks.com/topic/83074-putting-mysql-results-into-an-array/#findComment-422618 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.