I have a mysql DB with those column id , idUser , idCompany , idProfession for users table.
Now i would Select all those field and make an array that is build in this way :
array[idUser] = array [id=> x , idCompany => xx , idProfession => xxx)
For example 1 user could work for more company and do different profession.
So each array[idUser] Could have multiple array(id, idCompany,idProfession) and i would have 1 result for each idUser instead multiple result for the same idUser.
Now after i did the query i wrote this code but of course id doesnt do what i want becouse it replace always the same element with another one cause the while loop.
$data=array();
$sql_result="SELECT etc...........";
while($rows = mysql_fetch_array($sql_result,MYSQL_BOTH)){
$data[idUser] = array('idCompany' => $rows['idCompany'], 'profession' => $rows['idProfession'] );
I was thinking to do a for loop in the while , store the data in a tmp array.
But i had to stop becouse i didnt understand how to do that.
Does this do what you want?
This will populate the array like this: