Jump to content

Grouping items into an array from database


redbrad0

Recommended Posts

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);
  }

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
	        )


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.