Jump to content

PHP array building help please


jucedupp

Recommended Posts

Hi there guys,

 

I would truly appreciate any help you could give me on this:

 

PHP/MySql

 

I have a form that posts an array back to itself:

 

The post array looks like this:

 

Array ( [0] => 1 [1] => 2)

 

I then loop through the array as $type:

 

The query:

 

SELECT i.name, d.price, d.date FROM data d INNER JOIN items i ON (d.item_id = i.id) WHERE i.id = '.$type.' ORDER BY i.name

 

For each of the array I get this:

 

peanuts, 1000, 20100401

peanuts, 1100, 20100402

tomatoes, 400, 20100401

tomatoes, 401, 20100402

 

etc

 

What I need in the end is an array that looks like this:

 

Array ( [Peanuts] => Array ( [20100401] => 1000 [20100402] => 1100 ) [Tomatoes] => Array ( [20100401] => 400 [20100402] => 401 ) )

 

Can anyone help me to construct the query/loop that will achieve this?

If you could just use the above data, it would be perfect.

 

Any help would be sincerely appreciated and the person(s) who help with this will get an honorable mention and link in the source.

 

Cheers

 

Jacques

 

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.