PHP: Sorting MySQL result to multi-dimensional array -
now i'm tryin' sort mysql result multi-dimensional array type
line in sql so, that's code:
function gettablevalues($table_name) { // $link = connect_db(); $front_end_query = "select * `".$table_name."` `type` = 'front_end'"; $front_end_query_result = mysql_query($front_end_query); $cur_row = 0; /*while ($line = mysql_fetch_assoc($queryresult)) { $values = $line; $cur_row++; }*/ $front_end = mysql_fetch_assoc($front_end_query_result); $i=0; while ($line = mysql_fetch_assoc($front_end_query_result)){ #if ($line['type'] === 'front_end'){ # $line[$line['type']][$line['name']] = $line['value']; # $line[$line['type']][$line['name']]['desc'] = $line['description']; # $line[$line['type']][$line['name']]['visible_name'] = $line['visible_name']; # $line[$line['type']][$line['name']]['write_roles'] = $line['write_roles']; # $line[$line['type']][$line['name']]['read_roles'] = $line['read_roles']; #} $values['front_end'][$line['name']] = $line; $i++; } homecoming $values; }
and mysql table:
id type write_roles read_roles name value description visible_name 1 front_end 0 title sometitle exampletitle title 2 front_end 0 description somedesc illustration description
and that's want get:
$config[(sometype)][(somename)] = (value of line) $config[(sometype)][(somename)][(someoption)] = (value of option)
e.g.: $config['front_end']['title']['description']
returns exampletitle
how can that?
upd0: tried echo
array foreach
, , it's returned just 1 row db. doing wrong?
$values = array(); //base array while ($line = mysql_fetch_assoc($front_end_query_result)){ //fetch rows //in base of operations array create new array under 'name' $values[$line['name']] = array(); //for each item in result set, add together new array foreach ($line $key => $value) { $values[$line['name']][$key] = $value; } }
php mysql arrays
No comments:
Post a Comment