Jump to content

table to array help. so simple.


chaost

Recommended Posts

Hi,

 

This is bugging me and should be soooooo simple. Help please!

 

I have a myslq table with 3 fields.

<id><item><result>.

1  fish    15

4  cats    10

6  frogs  50

 

I need to build an array like this

 

array(

        [1] => array([item] => fish,  [result] => 15),

        [4] => array([item] => cats, [result] => 10),

        [6] => array([item] => frogs,[result] => 50)

)

 

thank you very much in advance for the help!!!

 

 

Link to comment
https://forums.phpfreaks.com/topic/92484-table-to-array-help-so-simple/
Share on other sites

totally confused.  didn't you just build the array? lol

 

<?php
$array = array();
// MYSQL DATABASE LOOP FUNCTIONALITY (assuming you're using MYSQL)
while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
    array_push($array,$row['id'] => array([item] => $row['item'],  [result] => $row['result']));
}
?>

 

Just to note, I didn't test this and just wrote it out here, so may need tweaking but should work just fine.

 

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.