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_」の各列の値を取得する必要があります。どのビューでも、これらの値を使用してフォームを作成する必要があります。配列を見てみましょう。

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_QTYているだけです。O_RC

私は間違って何をしていますか?

4

1 に答える 1

1

それぞれの最後の結果オブジェクトのみを返します。つまり、設定しています

$qO_Array = $qO->result_object();

変数に変換します。次のようになります。

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

それらすべてを取得するには

ところで-通常のresult()またはresult_array()の代わりにresult_object()を呼び出す特定の理由がありますか?必ずしも間違っているわけではありませんが、意図的にやっているのではないでしょうか。

于 2012-11-03T09:56:13.510 に答える