MySQL Forums
Forum List  »  PHP

Re: mySQL query result from multiple tables to PHP
Posted by: Mike Hughes
Date: February 17, 2006 01:14AM

I am not sure if this would be considered a proper PHP/MySQL solution, but if I had to do something like that, I would probably create an multidimensional array of the data you're pulling, for example:

$userArray = array( array("user_id"=>1, "user_name"=>"Mike", "group_name"=> array("group1", "group2") ) );

as you're looping through the result set, you could check to see if the user_id is in the array (in_array), if no, create a new element, if yes, check to see if the group name exists, if not, array push the new group name into the group_name array.

you could access the group_name array by:
print_r($userArray[0][group_name]);

and a single element by:
echo $userArray[0][group_name][0];

Again, that might be a very round about way of doing it, but to put the data together the way you illustrated, that's the only solution I know of.

Hope that helps.

mike h

Options: ReplyQuote


Subject
Written By
Posted
Re: mySQL query result from multiple tables to PHP
February 17, 2006 01:14AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.