Re: Array problems in PHP 4...
Posted: Mon Aug 17, 2009 1:04 pm
Okay, it looks like I have it now. The query needed the RLIKE clause -
Now all I have is 1 more little issue and it will finally be complete. I'm having problems getting the correct values from the arr_combine function (all because of PHP 4! arg!). The query has everything I need in it, but my understanding of array manipulation is what's coming into play now--but I'm getting there! Regardless, the returned query gives me the following:
Those users above are the only ones with administrative privileges. The ids are even accurate! The only thing I need to do now is make an array where the keys are those ids and the values are the usernames. Below is everything I'm using to achieve this to no avail as the array is not accurate:
Any ideas?
Code: Select all
$query = "SELECT id, user_login FROM $vtldb->users INNER JOIN $vtldb->usermeta ON $vtldb->users.id = $vtldb->usermeta.user_id WHERE $vtldb->usermeta.meta_value RLIKE 'administrator' ORDER BY id ASC LIMIT 10000";Code: Select all
Array ( [0] => stdClass Object ( [id] => 1 [user_login] => Walter ) [1] => stdClass Object ( [id] => 2 [user_login] => beckka ) [2] => stdClass Object ( [id] => 4 [user_login] => test2 ) )Code: Select all
function arr_combine($arr1,$arr2){//users then ids
if(!is_array($arr1))
$arr1 = array();
if(!is_array($arr2))
$arr2 = array();
$keys1 = array_keys($arr1);
$keys2 = array_keys($arr2);
$vals1 = array_values($arr1);//store all admin login names... WORKS.
$vals2 = array_values($arr2);//store all id numbers... WORKS.
$keys = array_merge($keys1,$keys2);
$vals = array_merge($vals1,$vals2);
$ret = array();
foreach($keys as $key){
list($unused,$val) = each($vals);
$ret[$key] = $val;
}
return $ret;
}
function get_vtl_user_roles(){
global $vtl_roles,$vtldb;
$this_role = "'[[:<:]]administrator[[:>:]]'";
$query = "SELECT id, user_login FROM $vtldb->users INNER JOIN $vtldb->usermeta ON $vtldb->users.id = $vtldb->usermeta.user_id WHERE $vtldb->usermeta.meta_value RLIKE 'administrator' ORDER BY id ASC LIMIT 10000";
$result = $vtldb->get_results($query);
print_r($result);
foreach ($result as $id=>$user) {
$partA[] = $user->user_login;
$partB[] = $user->id;
}
$users_of_this_role = arr_combine($partA,$partB);
return $users_of_this_role;
}