0

模型

    function get_prices() 
    {
        $table_by_product = 'printer_businesscards'; //replace with URI Segment
    
        //Get all the columns in the table set by the page URI of $table_by_product variable 
        $get_all_col_names = $this->db->list_fields($table_by_product);
        
        //Loop through the column names. All names starting with 'O_' are optional fields for the 
        //current product. Get all Distinct values and create a radio button list in form.
        foreach ($get_all_col_names as $key => $value) {
            //get all o_types for the product by column name
            if ($all_O_types = preg_match('/O_/', $value)) 
                {
                $O_types = array($value);
                foreach ($O_types as $O) {
                        //echo $O;
                        $this->db->select($O);
                        $this->db->distinct();
                        $qO = $this->db->get($table_by_product);
                        $qO_Array = $qO->result_object();
                    }
                } 
            //Get all x_types for the product by column name. All 'X_' types are specific product options.
            //Create a dropdown menu with all DISTINCT product options.
            if ($all_X_types = preg_match('/X_/', $value)) 
                {
                $X_types = array($value);
                    foreach ($X_types as $X) {
                        //echo $X;
                        $this->db->select($X);
                        $this->db->distinct();
                        $qX = $this->db->get($table_by_product);
                        $qX_Array = $qX->result_object();
                    }
                }       
        }
        return array($qX_Array,$qO_Array);
    }
}

所以每个产品都有不同的选项,但所有产品选项都以“X_”或“O_”为前缀。我需要获取DISTINCT“X_”和“O_”的每个 COLUMN 的值,并且在任何视图中我需要使用这些值构建一个表单。下面看一下数组:

array (size=3)
  0 => 
    object(stdClass)[19]
      public 'X_SIZE' => string '1.75x3' (length=6)
  1 => 
    object(stdClass)[20]
      public 'X_SIZE' => string '1.75x3.5(slim)' (length=14)
  2 => 
    object(stdClass)[21]
      public 'X_SIZE' => string '2x3' (length=3)
array (size=3)
  0 => 
    object(stdClass)[17]
      public 'X_PAPER' => string '14ptGlossCoatedCoverwithUV(C2S)' (length=31)
  1 => 
    object(stdClass)[18]
      public 'X_PAPER' => string '14ptPremiumUncoatedCover' (length=24)
  2 => 
    object(stdClass)[24]
      public 'X_PAPER' => string '16ptDullCoverwithMatteFinish' (length=28)
array (size=2)
  0 => 
    object(stdClass)[23]
      public 'X_COLOR' => string '1000' (length=4)
  1 => 
    object(stdClass)[22]
      public 'X_COLOR' => string '1002' (length=4)
array (size=4)
  0 => 
    object(stdClass)[20]
      public 'X_QTY' => string '100' (length=3)
  1 => 
    object(stdClass)[21]
      public 'X_QTY' => string '250' (length=3)
  2 => 
    object(stdClass)[17]
      public 'X_QTY' => string '500' (length=3)
  3 => 
    object(stdClass)[19]
      public 'X_QTY' => string '1000' (length=4)
array (size=3)
  0 => 
    object(stdClass)[25]
      public 'O_RC' => string 'YES' (length=3)
  1 => 
    object(stdClass)[26]
      public 'O_RC' => string 'NO' (length=2)
  2 => 
    object(stdClass)[27]
      public 'O_RC' => string 'NA' (length=2) 

我的电流MODEL只是回到我X_QTYO_RC视野。

我做错了什么?

4

1 回答 1

1

您只返回每个的最后一个结果对象;即,您正在设置

$qO_Array = $qO->result_object();

到一个变量,它应该是:

$qO_Array[] = $qO->result_object();

得到他们所有人

顺便说一句-您是否有特定原因调用 result_object() 而不是通常的 result() 或 result_array()?这不一定是错的,但我想知道你是否故意这样做?

于 2012-11-03T09:56:13.510 回答