Jump to content

Dividing data into multiple DIV's


Jim R

Recommended Posts

I have about 300 users, and I'm trying to group them geographically according what part of the state their county is in OR if they're reading my site because they have a favorite college team.  I've created a page that I want to show the total count for each group.  There will be 13 groups, and I'd rather not have 13 queries. 

 

Basically, I think, I can't make heads or tails of nested loops.

 

I'd like it to look like this:

 

 

Region 1 (## members)

Region 2 (## members)

Region 3 (## members)

etc.

...

...

...

...

...

 

 

I assume there will be IF and ElseIF statements.  Here is what I'm starting with, but I can't even get the first group working:

 

$query = 'SELECT * FROM wp_usermeta WHERE meta_key = "wp_1_s2member_custom_fields"';
$results = mysql_query($query);



while($line = mysql_fetch_assoc($results)) {
$meta_value = unserialize($line['meta_value']);

echo '<div>Region 1 (' . $d1 . ' Users)</div>';
if ($meta_value['county'] == '1' || $meta_value['county'] == '2') {

	++$d1;
}

};

Link to comment
Share on other sites

sorry, misunderstood your question.

something like this should work

$query = 'SELECT * FROM wp_usermeta WHERE meta_key = "wp_1_s2member_custom_fields"';
$results = mysql_query($query);

$region = array();

while($line = mysql_fetch_assoc($results)) {
$meta_value = unserialize($line['meta_value']);

$region[$meta_value['county']]++;

};

foreach ($region as $key => $value) {
echo "Region $key: $value members";
}

Link to comment
Share on other sites

That works, but I just discovered an issue with the data I need.  I need to also get

WHERE meta_value LIKE '%s2member_level2%'

.  The count has to be where both those conditions are met with the matching user_id.

 

This is all from the same table. 

 

Link to comment
Share on other sites

Yes.  Here is what I'm needing to query.

 

$member = 'SELECT * FROM wp_usermeta WHERE meta_value LIKE "%s2member_level%"';
$m_results = mysql_query($member);

$custom = 'SELECT * FROM wp_usermeta WHERE meta_key = "wp_1_s2member_custom_fields"';
$c_results = mysql_query($custom);

 

The columns are user_id, meta_key, meta_value.  Keep in mind, what Joel put together worked perfectly, but as I went to implement it, I realized I didn't fully understand what I was needing.  You might be able to use that as a guide.

 

What he wrote provided a total numbers of Users live in each region (based on which county they live in).  The number I need is among those, which ones are subscribers.

 

 

Link to comment
Share on other sites

Assuming you have a user id column in wp_usermeta to identify the user:

 

$custom = 'SELECT * FROM wp_usermeta WHERE meta_key = "wp_1_s2member_custom_fields" AND user_id IN (SELECT user_id FROM wp_usermeta WHERE meta_value LIKE "%s2member_level%")';
$c_results = mysql_query($custom);

 

The idea is for MySQL to check which users are subscribers and make a list of their user ids, and then restrict the custom_fields query by that list of user ids.

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.