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
https://forums.phpfreaks.com/topic/234484-dividing-data-into-multiple-divs/
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";
}

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.

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.