Jump to content

Trouble with using serialized data...


Jim R

Recommended Posts

  • Replies 51
  • Created
  • Last Reply

Top Posters In This Topic

It wasn't just about the variable but the location of the IF loop. 

 

$subscriptionLevels = array(
    's2member_level3' => 'Yearly',
    's2member_level2' => 'Semi-annual',
    's2member_level1' => 'Monthly'
);

$query = 'SELECT um1.meta_value as custom, um2.meta_value as level, u.ID,u.user_login, u.user_email
           FROM wp_usermeta um1 
           INNER JOIN wp_usermeta um2
             ON um1.user_id = um2.user_id
           JOIN wp_users u
             ON um1.user_id = u.ID
           WHERE um1.meta_key = "wp_s2member_custom_fields"
             AND um2.meta_value LIKE "%s2member_level%"
		 GROUP BY um1.user_id';

$result = mysql_query($query);

//Process results into temp array
$regionData = array();
while($row = mysql_fetch_assoc($result))
{    
    //var_dump($row);

    $custom = unserialize($row['custom']);
    $user_region = $custom['county'];
    $level = unserialize($row['level']);
    $level_desc = key($level); //E.g. s2member_level3

if ($level_desc != "s2member_level4") {	
    $user_level = $subscriptionLevels[$level_desc];
}

    if(!isset($regionData[$user_region]))
    {
        $regionData[$user_region] = array_fill_keys($subscriptionLevels, 0);
    }
    $regionData[$user_region][$user_level]++;
}

//Output the results

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";
}

}
}

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.