zohab Posted March 16, 2011 Share Posted March 16, 2011 Hi, I want to develop array like following $BCD=array('type' =>'TYPE1', array( 0=>array('column1'=>'value1','column2'=>'value1','column3'=>'value1','column4'=>'value1','column5'=>'value1','column6'=>'value1','column7'=>0), 1=>array('column1'=>'value1','column2'=>'value1','column3'=>'value1','column4'=>'value1','column5'=>'value1','column6'=>'value1','column7'=>0), 2=>array('column1'=>'value1','column2'=>'value1','column3'=>'value1','column4'=>'value1','column5'=>'value1','column6'=>'value1','column7'=>0), 3=>array('column1'=>'value1','column2'=>'value1','column3'=>'value1','column4'=>'value1','column5'=>'value1','column6'=>'value1','column7'=>0), ) )); I have written following code to achieve the same but not getting result. $sql = "select * from tablename "; $result = mysql_query($sql); $k=0; while ($row = $db->mysql_fetch_array($result)) { // array_push($BCD['type'],$row['type']); $BCD1=array('type' =>$row['type'], array( $k=>array('column1'=>$row['column1'],'column2'=>$row['column2'],'column3'=>$row['column3'],'column4'=>$row['column4'], 'column5'=>$row['column5'],'column6'=>$row['column6'],'column7'=>$row['column7']) )); $k++; } Link to comment https://forums.phpfreaks.com/topic/230807-creating-array-from-sql-query-data/ Share on other sites More sharing options...
AbraCadaver Posted March 16, 2011 Share Posted March 16, 2011 You're not going to be able to create an array like that if you have multiple types. Is it only TYPE1? Link to comment https://forums.phpfreaks.com/topic/230807-creating-array-from-sql-query-data/#findComment-1188228 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.