I've had a lot of help with this code, especially the isset stuff. I've gotten it about the way I want it, except how to utilize $collegeSubs array. I could easily change the form options that my users fill out, but I'm also trying to learn more about foreach/arrays.
The output I'm having issues with is down at the bottom of the code.
Here is the code:
$subscriptionLevels = array(
's2member_level2' => 'Yearly',
's2member_level1' => 'Semi-annual'
);
$collegeSubs = array(
'hsbball' => 'High School',
'bsu' => 'Ball State',
'bu' => 'Butler',
'cross' => 'Crossroad Conference',
'ue' => 'Evansville',
'glvc' => 'Great Lakes Valley Conference',
'iu' => 'Indiana',
'ipfw' => 'IPFW',
'iupui' => 'IUPUI',
'isu' => 'Indiana State',
'nd' => 'Notre Dame',
'pu' => 'Purdue',
'valpo' => 'Valparaiso'
);
$query = 'SELECT um.meta_value as level, um.meta_key, u.* FROM wp_usermeta AS um
JOIN wp_users AS u
ON um.user_id = u.ID
WHERE u.region IS NOT NULL
AND u.reason IS NOT NULL
AND um.meta_value LIKE "%s2member%"
GROUP BY u.ID asc
ORDER BY reason,region,u.user_login';
$result = mysql_query($query);
//Process results into temp array
$regionData = array();
$reason = array();
$reasonData = array();
while($row = mysql_fetch_assoc($result))
{
// var_dump($row);
$user_region = $row['region'];
$user_reason = $row['reason'];
// Keep this - This determines the subscription of level of the user
$level = unserialize($row['level']);
$level_desc = key($level); //E.g. s2member_level3
if ($level_desc != "s2member_level4") {
$user_level = $subscriptionLevels[$level_desc];
}
// This ends the subscription level of the user
if($user_reason == 'hsbball') {
if(!isset($regionData[$user_region]))
{
$regionData[$user_region] = array_fill_keys($subscriptionLevels, 0);
}
$regionData[$user_region][$user_level]++;
//end if
}
elseif($user_reason !='hsbball') {
if(!isset($reasonData[$user_reason]))
{
$reasonData[$user_reason] = array_fill_keys($subscriptionLevels, 0);
}
$reasonData[$user_reason][$user_level]++;
//end else
}
}
//Output the HS Region results
echo '<div class="region">';
//var_dump($regionData);
foreach ($regionData as $region => $data)
{if ($region != 0) {
echo "<br>Region {$region}<br>\n";
foreach($data as $subscription_type => $member_count)
{
//var_dump($subscription_type);
echo "{$subscription_type}: {$member_count} members<br>\n";
}
}
}
echo '</div>';
//Output the College results - this is what needs work
echo '<div class="reason"><p>';
foreach($reasonData as $reason => $reasData)
{
echo "College {$reason}<br>\n";
//}
foreach($reasData as $subscription_type => $member_count)
{
echo "{$subscription_type}: {$member_count} members<br>\n";
}
echo '<br>';
}
echo '</p></div>';
The output is pretty darn close to what I want. In the second section below, it's using the initials I have set up in the form. I'd like it to show the entire name of the college, which is reflected in the $collegeSubs array.
Here is the output: (They're not completely styled yet, but the divs are both float: left)
Region 1
Yearly: 1 members
Semi-annual: 0 members
Region 2
Yearly: 1 members
Semi-annual: 0 members
Region 3
Yearly: 1 members
Semi-annual: 0 members
College bu
Yearly: 0 members
Semi-annual: 0 members
: 1 members
College glvc
Yearly: 1 members
Semi-annual: 0 members
College ipfw
Yearly: 1 members
Semi-annual: 0 members
College isu
Yearly: 1 members
Semi-annual: 0 members
College iu
Yearly: 2 members
Semi-annual: 0 members
College iupui
Yearly: 1 members
Semi-annual: 0 members
College pu
Yearly: 1 members
Semi-annual: 0 members
College ue
Yearly: 1 members
Semi-annual: 0 members
College vu
Yearly: 1 members
Semi-annual: 0 members