SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question MySQL query in Wordpress... Sorry if this is in the wrong place...

    I'm trying to retrieve all users who are admins out of the wp_users table, but in this query, all I wish to retrieve is the user_login and user_id columns. MySQL is by far nothing I build any reputation around, so I'm no genius with it. Regardless, the following query is where I am at the moment and I can't understand why the user_id isn't showing up:

    Code:
    SELECT DISTINCT user_login FROM wp_users WHERE ID = ANY (SELECT DISTINCT user_id FROM wp_usermeta WHERE met_value RLIKE 'administrator');

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Because the only column you select is user_login.

    Code:
    SELECT DISTINCT user_login FROM...
    ->

    Code:
    SELECT DISTINCT user_id, user_login FROM

  3. #3
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You rock Dan. You just answered so many questions for me...

  4. #4
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry to do this to ya Dan, but I have 1 more question about looping through the returned result.


    This is where I am now:
    Code:
    	$query = "SELECT DISTINCT id, user_login FROM $vtldb->users WHERE ID = ANY (SELECT DISTINCT user_id FROM $wpdb->usermeta WHERE meta_value RLIKE 'administrator') ORDER BY ID ASC LIMIT 10000";
    	$users_of_this_role[] = $wpdb->get_results($query);
    	foreach($users_of_this_role as $id=>$user){
    		echo $id.'=>'.$user.'<br />';
    	}
    What do I need to do to traverse the resulting array? I've tried using a foreach in the following way:

    Code:
    	foreach($users_of_this_role as $id=>$user){
    		echo $id.'=>'.$user.'<br />';
    	}
    But this only outputs the following:
    Code:
    0=>Array
    Which makes me think it's a multi-dimensional array. I don't know how to traverse that correctly to get what I have in the query result. I tried the following in spite:

    Code:
    	foreach($users_of_this_role[0] as $id=>$user){
    		echo $id.'=>'.$user.'<br />';
    	}
    But then it gave me this error message:
    Catchable fatal error: Object of class stdClass could not be converted to string
    Any ideas?

  5. #5
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I think get_results returns an array of objects.

    PHP Code:
    $query "SELECT DISTINCT id, user_login FROM $vtldb->users WHERE ID = ANY (SELECT DISTINCT user_id FROM $wpdb->usermeta WHERE meta_value RLIKE 'administrator') ORDER BY ID ASC LIMIT 10000";
    $result $wpdb->get_results($query);
    foreach (
    $result as $user) {
        echo 
    $user->user_login;


  6. #6
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Dan! That got it. Finally!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •