• I am wanting to create a list of locations (ie States) with each location showing the NUMBER of users per location. I would add a custom field to the registration form (user_location) and then I would want the list to show like this:

    Alabama (22)
    Alaska (3)
    Arizona (122)
    … etc.

    Any ideas how I could do this?

Viewing 1 replies (of 1 total)
  • this might help, assume you have ‘location’ in your user table.

    $items = $wpdb->get_results('SELECT DISTINCT location FROM wp_tbluser');
    
    for ( $i=0 ; $i < count($items) ; $i++ ) {
      $item = $wpdb->get_results('SELECT location, count(*) AS c FROM wp_tbluser WHERE location=\''.$items[$i]->location.'\'');
    
      echo $item[0]->location . '&nbsp;&nbsp;&nbsp;(' . $item[0]->c . ')<br/>';
    }

    there might be other better solution for this 🙂

Viewing 1 replies (of 1 total)
  • The topic ‘Display Number of users per location?’ is closed to new replies.