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
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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.