Jump to content

putting mysql results into an array...


MikeDXUNL

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/83074-putting-mysql-results-into-an-array/
Share on other sites

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 />";
}

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 :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.