MySQL query to display multidimensional array

I am attempting to create a calendar that is displayed as follows:
[table]
[tr]
[td]Date[/td]
[td]Consultant1[/td]
[td]Consultant2[/td]
[td]Consultant3[/td]
[/tr]
[tr]
[td]6/25/13[/td]
[td]client1 | event_type1[/td]
[td]client2 | event_type1[/td]
[td]client1 | event_type2[/td]
[/tr]
[tr]
[td]6/26/13[/td]
[td]client1 | event_type2[/td]
[td]client2 | event_type3[/td]
[td]client1 | event_type1[/td]
[/tr]
[/table]
…etc

In my database, I have the following tables>>columns

[ul][li]billing_status>>billing_id, billing_type, billing_color[/li]
[li]calendar_event>>calendar_event_id, consultant_id, client_id, event_id, billing_id, date[/li]
[li]client>>client_id, client_name[/li]
[li]consultant>>consultant_id, f_name, l_name[/li]
[li]dates>>date (Note: Each date is used only once and they are used as the table’s key, but not all dates are used. This table serves as an ‘inventory’ of available dates.[/li]
[li]event_type>>event_id, event_type, event_full_name[/li][/ul]

I am attempting to generate an array that combines all of the different dimensions using the following:
[php]

<?php mysql_select_db($connection); //connection details removed in this post for obvious reasons, but they are correct in my file $query = "SELECT * FROM calendar_event ce LEFT JOIN billing_status bs ON ce.billing_id = bs.billing_id LEFT JOIN client cl ON ce.client_id = cl.client_id LEFT JOIN consultant co ON ce.consultant_id = co.consultant_id LEFT JOIN dates dt ON ce.date = dt.date LEFT JOIN event_type et ON ce.event_id = et.event_id GROUP BY ce.consultant_id, ce.date ORDER BY ce.date"; $consultantresults = mysql_query($query) or die ('Query failed: ' . mysql_error()); echo ""; while ($consultantresult=mysql_fetch_array($consultantresults)) { $name = $consultantresult[f_name] . " " . $consultantresult[l_name]; $consultant = array($name); foreach ($consultant as $consultants) { echo ""; } echo ""; } while ($consultantresult=mysql_fetch_array($consultantresults)) { $events = array( $consutantresult[date]=>array( $consultantresult[billing_color]=>array( $consultantresult[client_name]=>array( $consultantresult[event_type] ) ) ) ); echo ""; foreach ($events as $date=>$billing=>$client=>$type) { echo ""; } echo ""; echo "
Date" . $consultants . "
" . $date . " " . $client . " | " . $type . "
"; } ?> [/php]

However all this produces for me is a blank page. Even when I “view source” of the page, it doesn’t even have the tags.

Is there another way to do this? My database is only populated with “sample” data right now, so even if I had to restructure the database, I wouldn’t be opposed to it.

reading through your code, there’s a few things to change…

first you have a typo in the second while loop, second array variable name:
[php]$consutantresult[date]=>array( [/php]

Next, put single quotes around the array names like so:
[php]$consultantresult[‘date’]
$consultantresult[‘f_name’][/php]

If you put this line at the top of your page, you ‘should’ see an error if problems, rather than a blank page:
[php]<?php ini_set('display_errors', 1); ?>[/php]
Note: do NOT use this last line on a live website!

After you have made these changes, let me know how you get on.
Red :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service