0

クエリ結果

Array
(
[0] => stdClass Object
    (
        [ingredientID] => 2
        [code] => Bf
        [description] => 1st Class Flour
        [volume] => 8268
        [price] => 750
        [amount_gram] => 0.02980
        [status] => Inactive
        [uom_id] => 1
        [flour] => Yes
    )

[1] => stdClass Object
    (
        [ingredientID] => 3
        [code] => Sf
        [description] => 3rd Class Flour
        [volume] => 18490
        [price] => 635
        [amount_gram] => 0.02540
        [status] => Inactive
        [uom_id] => 5
        [flour] => Yes
    )
..........

この結果を行インベントリとして別のテーブルに保存したいと思います。テーブルは次のようになります。

ID        inventory
1         (the result)
2         (another result)

そして、結果を表示できるように、もう一度クエリを実行します。

これが私が最近やったことです。

お店:

//getting the result
$inv = $this->db->get_from('table','id'=>'1')->row();
<input type="hidden" name="inventory" value="<?php print_r($inv)?>">
//storing in the new table
$this->db->insert('table2',array('inventory'=>$this->input->post('inventory')));

取得:

$inventory = $this->db->get_where('table2',array('ID'=>'1'))->row_array();
//result
array
(
      [ID] => 1
      [inventory] =>
      array
      (
            [0] => stdClass Object
            (
                 [ingredientID] => 2
                 ...... and so on

オブジェクトの配列であるarray['inventory']内のすべてを表示したいと思います。

私はこれをforeach($ arr ['inventory'] as $ Inventor)で実行しました:echo $ invent ['ingredientID'];

しかし、foreach部分にエラーがあります。エラー:foreach()に無効な引数が指定されました

私は何をすべきか?endforeach;

4

1 に答える 1

1

仮定:

$results = $this->db->get_where('table2',array('ID'=>'1'))->row_array();

これを使用して印刷する必要があります

foreach($results['inventory'] as $inventory)
{
    print_r($inventory->ingredientID);
}
于 2012-06-08T09:43:59.947 に答える