dawnw Posted June 9, 2010 Share Posted June 9, 2010 I need to add each $value into an array and I can't figure it out. I can echo and print them all individually but I want the values in 1 array so I can sort and count. Any help is greatly appreciated. Code is below. $data2=$db->select("SELECT * FROM database"); foreach ($data2 as $key => $value) { echo $value['Name']; } Link to comment https://forums.phpfreaks.com/topic/204298-get-values-from-foreach-into-an-array/ Share on other sites More sharing options...
premiso Posted June 9, 2010 Share Posted June 9, 2010 $data2 = $db->select("SELECT * FROM database"); foreach ($data2 as $key => $value) { if ($key == "Name") { $value['Name'][] = $value; } } print_r($value); Not sure why you are taking them from one array and making another, but there you have it. Link to comment https://forums.phpfreaks.com/topic/204298-get-values-from-foreach-into-an-array/#findComment-1069996 Share on other sites More sharing options...
dawnw Posted June 9, 2010 Author Share Posted June 9, 2010 Here is the complete code: I am trying to group $info['Name'] and then do a count for each group. So Group 1 = 25, Group2 = 4, etc. Any help is greatly appreciated. $child=$db->select("SELECT C.Number_ID, V.Name, C.Parent_Number_ID FROM Customer_Gifts as C, Numbers as N, Gifts as V WHERE N.ID=368 AND N.ID=V.ID AND N.Number_ID=C.Parent_Number_ID"); if ($child){ foreach ($child as $c){ $children[]=$c['Number_ID']; } } $data=$db->select("SELECT C.Number_ID FROM Customer_Gifts AS C, Numbers AS VN WHERE ID = 368 AND VN.Number_ID=C.Parent_Number_ID "); $result=$db->select("SELECT * FROM Numbers WHERE ID = 368 AND Status_ID = 5"); $number = count($result); echo "<br />Total 3S Redeemed: ".$number."<br />\n"; foreach ($data as $parent) { $data2=$db->select("SELECT V.Name FROM Gifts AS V, Numbers AS VN WHERE VN.ID=V.ID AND VN.Number_ID = ".$parent['Number_ID']." ORDER BY Name ASC"); foreach ($data2 as $info) { echo $info['Name']."<br />"; } } } } Link to comment https://forums.phpfreaks.com/topic/204298-get-values-from-foreach-into-an-array/#findComment-1070016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.