这是从我的模型返回的 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;
}