i want to build an object (for angular) so it will look like so
user:{
{education:
{high school:'some school'},
{faculty:'faculty of science'}
},
{skills:
{skill1:'sk1'},
{skill2:'sk2'}
}
}
and this is my php and mysql query:
$testArr = array();
$user = new stdClass();
$params = DB::select( DB::raw("SELECT param.*, sys_param_values.*,param_value.*,type_user.*,
param.name AS paramName,
doc_param.name AS docParamName
FROM param
LEFT JOIN doc_param ON param.doc_param_id = doc_param.id
LEFT JOIN sys_param_values ON param.id = sys_param_values.param_id
LEFT JOIN param_value ON sys_param_values.value_ref = param_value.id
LEFT JOIN type_user ON sys_param_values.ref_user_id = type_user.id"));
query result:
"params":[{"id":21,"name":"faculty","type_id":5,"doc_param_id":14,"created_at":"2015-05-17 14:13:12","updated_at":"2015-06-04 08:19:43","doc_type":12,"ref_user_id":21,"param_id":48,"iteration":null,"value_short":null,"value_long":null,"value_ref":74,"value":"some High","type":"tech-admin","email":"[email protected]","password":"$2y$10$6L8voJ3DgZuADHZLaBh4jei\/U.svVdcN4B02XFc9mF\/p8m5RpfJtG","password_new":null,"first_name":"jon","last_name":"snow","street_1":"shiv","street_2":"tey","city":"123456","state":"aa","zipcode":"47252","country":"usa","phone_1":"123456","phone_2":"123456","mobile":"123456789","date_of_birth":"2015-05-18 11:25:42","registration":"0000-00-00 00:00:00","last_login":"2015-05-20 09:14:52","send_newsletters":1,"send_notifications":1,"remember_token":"dtlimLNZBWdCxcqKR7NdDblMiafkZOxywN4jjUac53v7NI4e1t6eokJXdsoy","paramName":"faculty","docParamName":"education"}
after the query witch is good, i loop :
foreach($params as $k=>$v) {
$paramName = $v->paramName;
$value = $v->value;
$testArr[$v->docParamName] = array();
$testArr[$v->docParamName][$paramName] = $v->value;
}
and the result is :
"test":{
"education":
{"high_school":"some High"},
"skills":
{"skill_1":"skill_1 Value"},
"experience":
{"xp_1":"xp1 value"}
}
the thing is i have more if these parameters for example "skill_2" and "skill_3" that are suppose to go in the "skills" object. but this loop anly gets the last parameter..
where am i suppose to specify a key or something so that all of the skills go to the skills object and so on..