繁体   English   中英

将查询结果作为行存储到数据库表中

[英]Store into a database table as row the query result

查询结果

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']为$ invent):echo $ invent ['ingredientID'];

但是foreach部分存在错误。 错误:为foreach()提供了无效的参数

我该怎么办? endforeach;

假设:

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

你应该用它来打印它

foreach($results['inventory'] as $inventory)
{
    print_r($inventory->ingredientID);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM