数组覆盖我的代码只有我得到的单个值

时间:2016-02-27 06:17:48

标签: php arrays codeigniter

我从数据库获取数据有那么多数据,所以我计划通过使用数组在不同的地方显示它但我尝试代码数组覆盖ian没有得到所有对象值可以任何身体清除这一个。

CodeIgniter controller code:
   public function compare_by_business_sectors(){
       //print_r($this->input->post());exit;
        if($this->input->post())
        {
            $solution_array = array();
                //print_r (json_encode($business_sectors));exit;
            $business_sectors=$this->home_model->compare_business_sectors_data($this->input->post());
           // print_r($business_sectors);exit;
            $tab_child_id = "";
             $id="";
            foreach($business_sectors as $key=>$sectors){
                        $solution_array[1]=$sectors->solution_name;
                        $solution_array[2]=$sectors->description;
                        $solution_array[3]=$sectors->vendor_name;
                        $solution_array[4]=$sectors->video_presentation;
                        $solution_array[5]=$sectors->start_free_trail;
                        $solution_array[6]=$sectors->hardware_package;
                        $solution_array[7]=$sectors->pos_market_rating;
                  $id = "solution".$sectors->tab_child_id;
                 $solution_array[$id]=array();
                 if($tab_child_id != $sectors->tab_child_id){
                     $solution_array[$id][$sectors->field_id] = $sectors->title;
                  $tab_child_id=$sectors->tab_child_id;
                 }
                 else {
                 $solution_array[$id][$sectors->field_id] = $sectors->title;
                 }
            }          
          }

          print_r($solution_array);
   }

model_code:

public function compare_business_sectors_data($sectorid){
                    $query = $this->db->select('solutions.*,solution_tabs_child_fields.field_id,solution_tabs_child_fields.tab_child_id,solution_tabs_child_fields.title')
                             ->from('solutions')
                             //->join('solutions', 'business_sector.sector_id = solutions.business_sector_id',"left")
                             ->join('solution_features','solutions.entry_id  = solution_features.entry_id',"left")
                             ->join('solution_tabs_child_fields','solution_features.field_id = solution_tabs_child_fields.field_id')
                            ->where('solutions.business_sector_id', $sectorid['id'])
                            ->get();
                            return $query->result();

1 个答案:

答案 0 :(得分:0)

将其用作

while (nodeItr.hasNext()) {
                    Node cNode = nodeItr.nextNode();
                    if (cNode.hasProperty("country")) {
                        JSONObject jsonData = new JSONObject();
                        jsonData.put("country", childNode.getProperty("countryname").getValue().getString());
                        jsonArray.put(jsonData);
                        if (cNode.hasProperty("states")) {
// This should display array of all states as an when it is encountered.
LOG.info(childNode.getProperty("states").getValue().getString());