Hello,
I'm looking for some help with this array that I'm trying to build. Basically, I'm searching a database table for workshops that take place on or after todays date. A workshop can have the same workshop id ($ws_id[$i]) but can have up to four different dates. I'm trying to sort through the result and create a new array if the workshop id is different from the previous. If it is the same then I just want to add the date ($wsDate[$i]) and date id ($wsDate_id[$i]) to the existing array for that workshop id.
THANKS!!! Chris
This is what I've come up with but it is working very strangely!
<?php
$i = -1;
$workshop_count =0;
do {
$i++;
$ii = $i -1;
$wsDate_id[$i] = $row_workshopDate['workshopDate_id'];
$ws_id[$i] = $row_workshopDate['workshop_id'];
$wsDateINT_id[$i] = $row_workshopDate['workshop_dateINT'];
$wsDate[$i] = $row_workshopDate['workshopDate_date'];
if($ws_id[$i] !== $WS_DATA[$i]['workshop']['id']){
$workshop_count++;
$WS_DATA[$i]['workshop']['id'] = $ws_id[$i];
$WS_DATA[$i]['date']['0'] = $wsDate[$i];
$WS_DATA[$i]['date']['1'] ="";
$WS_DATA[$i]['date']['2'] ="";
$WS_DATA[$i]['date']['3'] ="";
$WS_DATA[$i]['dateID']['0'] = $wsDate_id[$i];
$WS_DATA[$i]['dateID']['1'] = "";
$WS_DATA[$i]['dateID']['2'] = "";
$WS_DATA[$i]['dateID']['3'] = "";
} else if($ws_id[$i] == $WS_DATA[$ii]['workshop']['id'] && $WS_DATA[$i]['date']['1'] == ""){
$WS_DATA['date'][$i]['1'] = $wsDate['1'];
$WS_DATA['dateID'][$i]['1'] = $wsDate_id['1'];
} else if($ws_id[$i] == $WS_DATA[$ii]['workshop']['id'] && $WS_DATA[$i]['date']['2'] == ""){
$WS_DATA[$i]['date']['2'] = $wsDate['2'];
$WS_DATA[$i]['dateID']['2'] = $wsDate_id['2'];
} else if($ws_id[$i] == $WS_DATA[$ii]['workshop']['id'] && $WS_DATA[$i]['date']['3'] == ""){
$WS_DATA[$i]['date']['3'] = $wsDate['3'];
$WS_DATA[$i]['dateID']['3'] = $wsDate_id['3'];
}
} while ($row_workshopDate = mysql_fetch_assoc($workshopDate));
?>
My database currently has 1 workshop in it with 4 date all of which are in the future. The above code returns:
Array
(
[workshop] => Array
(
[0] => Array
(
[id] => 174
)
)
[date] => Array
(
[0] => Array
(
[0] => February 2 2007
[1] =>
[2] =>
[3] =>
)
[1] => Array
(
[1] => May 4 2008
)
)
[dateID] => Array
(
[0] => Array
(
[0] => 63
[1] =>
[2] =>
[3] =>
)
[1] => Array
(
[1] => 64
)
)
)
workshop_count = 1
But I want it to return this:
Array
(
[0][workshop] => Array
(
=> Array
(
[id] => 174
[Date][0] => February 2 2007
[Date][1] => February 7 2007
[Date][2] => February 9 2007
[Date][3] => February 20 2007
[DateID][0] => 65
[DateID][1] => 66
[DateID][2] => 67
[DateID][3] => 68
)
)
)
workshop_count = 1
Or if there were two or more workshops something like this:
Array
(
[0][workshop] => Array
(
=> Array
(
[id] => 174
[Date][0] => February 2 2007
[Date][1] => February 7 2007
[Date][2] => February 9 2007
[Date][3] => February 20 2007
[DateID][0] => 65
[DateID][1] => 66
[DateID][2] => 67
[DateID][3] => 68
)
)
[1][workshop] => Array
(
=> Array
(
[id] => 175
[Date][0] => March 2 2007
[Date][1] => March 7 2007
[Date][2] => March 9 2007
[Date][3] => March 20 2007
[DateID][0] => 69
[DateID][1] => 70
[DateID][2] => 71
[DateID][3] => 72
)
)
)
workshop_count = 2