What is the problem with my mysql array extraction below:
$mysql_array = mysql_query("SELECT * FROM table1 WHERE uid1='$uid1'");
$array = array();
while($row = mysql_fetch_assoc($mysql_array)){
$array[] = $row;
}
$array = array_unique($array);
$array = array_reverse($array);
$emails = array();
$numbers = array();
foreach($array as $row){
$uid2 = $row['uid2'];
$number = number($uid2);
if(strlen($number) > 9){
$numbers[] = array('uid2' => $uid2, 'number' => $number);
}
else{
$email = email($uid2);
$emails[] = array('uid2' => $uid2, 'email' => $email);
}
}
$numbers = array_unique($numbers);
$emails = array_unique($emails);
var_dump($numbers);
var_dump($emails);
There must be something I need to do to convert the “Resource” from mysql into an array.
There must be a problem with the above code.
This is what I am getting on the var_dumps: array(0) { }
and array(1) { [0]=> array(2) { ["uid2"]=> NULL ["email"]=> NULL } }
I think this is what you’re trying to do:
EDIT Answering question from comments:
Based on the logic you are using, the result will probably be the same. My example above will allow this scenario for
$numbers, while your example will not:But based on the way that
$numberis generated based on$uid2, you probably won’t see any difference. What I mean is that, ifnumber(123)returns1234567890, thennumber(456)probably will not return1234567890, so you probably wouldn’t ever run into a scenario where you would see a difference.EDIT 2 After thinking about this some more, I’m betting that your code can be greatly simplified to this:
LAST EDIT (Hopefully):