473,408 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

mysql table into multidimensional array

Hi

Hope someone can help me with this!

I'm trying to get a table of data into a multidimensional array.

The table fields are as follows;

Expand|Select|Wrap|Line Numbers
  1. headline
  2. text
  3. startDate
  4. type
  5. media
  6. caption
  7. credit
  8.  
Only one row of data will have a value for field "type". There will eventually be dozens of other rows.

I need to place the data into an array with the following structure;

Expand|Select|Wrap|Line Numbers
  1. $array = array(
  2.  
  3.     "timeline" => array(
  4.         "headline" => "value",
  5.         "text" => "value",
  6.         "startDate" => "value",
  7.         "type" => "default",
  8.         "asset" => array(
  9.                 "media" => "value,
  10.                 "caption" => "value",
  11.                 "credit" => "value"
  12.                 ),
  13.         "date" => array(
  14.              "1" => array (
  15.             "headline" => "value",
  16.             "text" => "value",
  17.             "startDate" => "value",
  18.             "type" => "",
  19.             "asset" => array(
  20.                     "media" => "value,
  21.                     "caption" => "value",
  22.                     "credit" => "value"
  23.                     )
  24.                     ),
  25.              "2" => array (
  26.             "headline" => "value",
  27.             "text" => "value",
  28.             "startDate" => "value",
  29.             "type" => "",
  30.             "asset" => array(
  31.                     "media" => "value,
  32.                     "caption" => "value",
  33.                     "credit" => "value"
  34.                     )
  35.                     )
  36.         );
  37.  
  38.  
  39.  
All rows aside from the one where type="default" will be within "date".

I'm completely stuck with this. I've been trying to build the arrays from multiple variables, but it's just not working. I'll add that I'm still pretty new to PHP.

Any assistance you can offer with this would be MUCH appreciated!

Thank you.
Jul 3 '12 #1
2 2068
Luuk
1,047 Expert 1GB
How many/much records do you have in your table, (if you look at your example) ?

I think 6, but if that is not correct, i did not understand your problem.... ;)

The first part ('headline' - 'asset'):
This can be constructud using the MySQL query:
SELECT headline, text, startdate, type, group_concat(asset)
from table
where type='default'
group by headline, text, startdate, type


After thant you have to go one level deeper, to add the 'date' fields. this is basically a repitition of the above ;)
Jul 7 '12 #2
Claus Mygind
571 512MB
You may want to look at my response (best answer) in this link http://bytes.com/topic/php/answers/9...-fill-template

php does not use multidimensional arrays. They use arrays within arrays. The biggest difference here is in how to access the structure of the array.

Traditional multi arrays are referenced like this array[1,1]

where as php multi arrays are referenced like this
array[1][1];

But if you are looking to do a cross-tab report, you may want to download the code example I give in the answer.
Jul 9 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mark Smith | last post by:
I'm trying to copy data from a 1D array to a 2D array. The obvious thing doesn't work: int twoDee = new int; int oneDee = new int { 1, 2 }; Array.Copy(oneDee, 2, twoDee, 2, 2); This causes a...
2
by: chris | last post by:
Hi there, I created a Multidimensional array of labels Label lblMultiArray = new Label { {Label3, LblThuTotal}, {Label4,LblFriTotal} }; Now I would like to compare the values in the array,...
0
by: epigram | last post by:
Well, conceptually this is what I want to do. I was hoping to use an ArrayList to build a (dynamic) array of string arrays, and then bind the ArrayList object to a DataGrid. I can do that, but it...
3
by: BobbyS | last post by:
I am trying to develop a multidimensional array for use of searching a very large database. I understand the concept of one and two dimensional arrays but this project would include up to 12 or 13...
5
by: Stephen Preston | last post by:
Trying to load an multidimensional array into a MySQL table with columns as follows, level1,level2,level3,illust,item,description,partNo,qua,price,remarks,weight ,size,mass the array first...
10
by: | last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily complicated than the other languages I know. I feel this is because there aren't many good official resources out there to...
2
by: phattymatty | last post by:
I am having trouble getting this loop to do what I would like it to. I need to display information from a multidimensional array in order. The order has already been sorted in the array using a...
1
by: shailajaAdiga | last post by:
Hi All, there are 4 different categories which each month will bw updated. In each category(source),there are many editions. I have to display 6months updates. its like one is month array which...
4
Jezternz
by: Jezternz | last post by:
First of all I am open to any suggestions and advice. If a javscript multidimensional array is a bad way to do this please say so. I considered XML but I wondered if this would be a bad idea as it...
2
by: mouac01 | last post by:
Let's say I have this MySQL table. Year Region Amount 2007 West 100 2007 East 200 2007 North 300 2007 South ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.