redbrad0 Posted March 6, 2010 Share Posted March 6, 2010 This seems like a stupid question but I cant seem to figure it out. What I am trying to do is generate an array that looks like the below sample but have all the Member ID's group so I know the card each member grabbed. Array ( [889557275612] => Array ( [0] => Array ( [Cards_ID] => 51 [Cards_MemberID] => 889557275612 [Cards_Card] => 308292114653 [Cards_DateTime] => 1969-12-31 18:00:00 ) [1] => Array ( [Cards_ID] => 51 [Cards_MemberID] => 889557275612 [Cards_Card] => 308292114653 [Cards_DateTime] => 1969-12-31 18:00:00 ) ) [971131027757] => Array ( [0] => Array ( [Cards_ID] => 51 [Cards_MemberID] => 971131027757 [Cards_Card] => 308292114653 [Cards_DateTime] => 1969-12-31 18:00:00 ) ) ) $query = "SELECT * FROM Cards"; $res =& $db['tickets']->query($query); if (PEAR::isError($res)) throw new TixException($_SERVER['SCRIPT_NAME'] . ":", TixExceptionCodes::UNKNOWN_ERROR); $cardsGrouped = array(); while ($res->fetchInto($row)) { array_push($cardsGrouped[$row['Card_MemberID']], $row); } Quote Link to comment https://forums.phpfreaks.com/topic/194312-grouping-items-into-an-array-from-database/ Share on other sites More sharing options...
Redlightpacket Posted March 6, 2010 Share Posted March 6, 2010 Not really sure what you are talking about a little bit. But this is where I would start. Hopefuly this might help you some way. <?PHP $query = "SELECT * FROM Cards"; $result = mysql_query($query) or die("Query failed: " . mysql_error()); while ($row = mysql_fetch_assoc($result)) { $Cards_ID[1] = $row['Cards_ID']; $Cards_MemberID[1] = $row['Cards_MemberID']; $Cards_Card[1] = $row['Cards_Card']; $Cards_DateTime[1] = $row['Cards_DateTime']; } Array ( [889557275612] => Array ( [0] => Array ( [Cards_ID] => 51 [Cards_MemberID] => 889557275612 [Cards_Card] => 308292114653 [Cards_DateTime] => 1969-12-31 18:00:00 ) [1] => Array ( [Cards_ID] => 51 [Cards_MemberID] => 889557275612 [Cards_Card] => 308292114653 [Cards_DateTime] => 1969-12-31 18:00:00 ) ?> Quote Link to comment https://forums.phpfreaks.com/topic/194312-grouping-items-into-an-array-from-database/#findComment-1022227 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.