これは、モデルから返された var_dump または配列です。
array (size=5)
0 =>
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)
1 =>
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)
2 =>
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)
3 =>
array (size=4)
0 =>
object(stdClass)[26]
public 'X_QTY' => string '100' (length=3)
1 =>
object(stdClass)[25]
public 'X_QTY' => string '250' (length=3)
2 =>
object(stdClass)[29]
public 'X_QTY' => string '500' (length=3)
3 =>
object(stdClass)[30]
public 'X_QTY' => string '1000' (length=4)
4 =>
array (size=3)
0 =>
object(stdClass)[28]
public 'O_RC' => string 'YES' (length=3)
1 =>
object(stdClass)[27]
public 'O_RC' => string 'NO' (length=2)
2 =>
object(stdClass)[33]
public 'O_RC' => string 'NA' (length=2)
私のコントローラーは私のビューに送信しており、私のビューでは上記のダンプは次のとおりです。var_dump($printerOptions)
では、これらの配列ごとにドロップダウン メニューと、配列のラジオ ボタンを作成する必要がありますO_RC
。
私は codeigniter を使用しform_dropdown('',$val);
ており、 foreach ループ内で使用すると、配列内の各キーと要素に対して複数のドロップダウンが発生します。
foreach ($printerOptions as $Options)
{
//var_dump($Options);
foreach ($Options as $Specs)
{
echo $Specs->X_SIZE;
echo $Specs->X_PAPER;
echo $Specs->X_COLOR;
echo $Specs->X_QTY;
echo $Specs->O_RC;
}
}
この ^ コードは、対応する配列の期待値をエコーアウトしますが、何らかの理由で、出力で LOOPING エラーが発生します。
Undefined property: stdClass::$X_PAPER
Undefined property: stdClass::$X_COLOR
Undefined property: stdClass::$X_QTY
Undefined property: stdClass::$O_RC
配列を見て、各配列のドロップダウン メニューをそれぞれ作成するにはどうすればよいですか?
助けてくれてありがとう。
モデル /// 更新 ///
class M_Pricing extends CI_Model {
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.
$resultArray = array();
foreach ($get_all_col_names as $key => $value) {
//get all o_types for the product by column name
if (preg_match('/O_/', $value))
{
$v = (array('Specs' => $value));
foreach ($v as $vals) {
$this->db->select($vals);
$this->db->distinct();
$qX = $this->db->get($table_by_product);
$resultArray[] = $qX->result();
}
}
//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 (preg_match('/X_/', $value))
{
$v = (array('Type' => $value));
foreach ($v as $vals) {
$this->db->select($vals);
$this->db->distinct();
$qX = $this->db->get($table_by_product);
$resultArray[] = $qX->result();
}
}
}
//return $resultArray
//var_dump($resultArray); die;
return $resultArray;
}