1

我在控制器中有一个数组我必须将它发送到查看然后显示值

控制器页面代码

 public function showbookedmenu(){

 $rowLength=$this->input->post('rowno');
 $check=$this->input->post('checkeed');

    $j=0;
    for($i=1;$i<=$rowLength;$i++)
    {
        $check=$this->input->post('checkeed'.$i);

        if($check== "checked")
        {
        $orderedItem[$j][$i]   = $this->input->post('txtMenuItem'.$i);
        $orderedItem[$j][$i+1]  = $this->input->post('quantity'.$i);
        $orderedItem[$j][$i+2]    = $this->input->post('lebPrice'.$i); 
        $orderedItem[$j][$i+3]= $this->input->post('grandtotal'.$i); 
        $j++;
        }
        else{}
    }
    $data['order']= $orderedItem;
    $this->load->view('orderpage', $data);
 }

查看页面

What will be the code??

4

2 回答 2

4

首先像这样重写你的控制器动作:

public function showbookedmenu()
{
  $rowLength = $this->input->post('rowno');    
  $orderedItem = array();

  for($i = 1; $i <= $rowLength; $i++)
  {
    $check = $this->input->post('checkeed'.$i);

    if($check == "checked")
    {
      $orderedItem[] = array(
        'menu_item' => $this->input->post('txtMenuItem'.$i),
        'quantity' => $this->input->post('quantity'.$i),
        'leb_price' => $this->input->post('lebPrice'.$i),
        'grand_total' => $this->input->post('grandtotal'.$i)
      );
    }
  }

  $data['order'] = $orderedItem;
  $this->load->view('orderpage', $data);
}

然后在您看来,您可以这样做:

<? foreach($order as $order_item): ?>
  <? echo $order_item['menu_item']; ?>
  <? echo $order_item['quantity']; ?>
  <? echo $order_item['leb_price']; ?>
  <? echo $order_item['grand_total']; ?>
<? endforeach; ?>
于 2012-05-14T07:43:06.147 回答
0

首先尝试在视图文件中打印数组值..

print_r($order);

如果一切顺利的话..

你可以给它

foreach ($order as $value):

并使用它:

于 2012-05-14T07:23:57.993 回答