Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql Codeigniter-查看文件-批量从sql检索数据_Mysql_Codeigniter - Fatal编程技术网

Mysql Codeigniter-查看文件-批量从sql检索数据

Mysql Codeigniter-查看文件-批量从sql检索数据,mysql,codeigniter,Mysql,Codeigniter,这是我从模型文件到控制器的响应 array (size=2) 'wholesale_records' => array (size=2) 0 => object(stdClass)[36] public 'id' => string '117' (length=3) public 'product_id' => string '60' (length=2) public 'usertype' => string

这是我从模型文件到控制器的响应

array (size=2)
  'wholesale_records' => 
array (size=2)
  0 => 
    object(stdClass)[36]
      public 'id' => string '117' (length=3)
      public 'product_id' => string '60' (length=2)
      public 'usertype' => string 'wholesale' (length=9)
      public 'range' => string '1' (length=1)
      public 'uom' => string '3' (length=1)
      public 'price' => string '1' (length=1)
      public 'vat@' => string '1' (length=1)
      1 => 
    object(stdClass)[37]
      public 'id' => string '119' (length=3)
      public 'product_id' => string '60' (length=2)
      public 'usertype' => string 'wholesale' (length=9)
      public 'range' => string '3' (length=1)
      public 'uom' => string '3' (length=1)
      public 'price' => string '3' (length=1)
      public 'vat@' => string '3' (length=1)
  'wholesale_count' => int 2
但我想在我的输入占位符中显示这些,但显示时出错 这是我的视图文件

<?php
for ( $i = 0; $i < $wholesale['wholesale_count']; $i ++ ) { ?>
    <div class="section row" id="row1" style="margin-bottom:0px;">
        <div class="col-sm-3">
            <div class="form-group">
                <label class="field">
                    <input type="text" name="range1" id="amount"
                           class="gui-input" placeholder="<?php echo $wholesale['wholesale_records'][ $i ]['range']; ?>"
                           required>
                </label>
            </div>
        </div>
    </div>
<?php } ?>


您没有显示控制器或模型,也没有显示您得到的确切错误。在提供帮助方面,所有这些都是非常有用的。我要对这个问题作一个猜测。可能是这条线

placeholder="<?php echo $wholesale['wholesale_records'][ $i ]['range']; ?>"
使用
foreach(…)
通常比为(…)
循环设置
要容易得多。它不仅减少了输入,而且执行速度更快

看起来模型的回归可能比它需要的更复杂。 模型可以简单地以

return $query->result();
应该返回这样的结构

array (size=2)
  0 => 
    object(stdClass)[36]
      public 'id' => string '117' (length=3)
      public 'product_id' => string '60' (length=2)
      public 'usertype' => string 'wholesale' (length=9)
      public 'range' => string '1' (length=1)
      public 'uom' => string '3' (length=1)
      public 'price' => string '1' (length=1)
      public 'vat@' => string '1' (length=1)
      1 => 
    object(stdClass)[37]
      public 'id' => string '119' (length=3)
      public 'product_id' => string '60' (length=2)
      public 'usertype' => string 'wholesale' (length=9)
      public 'range' => string '3' (length=1)
      public 'uom' => string '3' (length=1)
      public 'price' => string '3' (length=1)
      public 'vat@' => string '3' (length=1)
你不需要把回报埋得更深,也不需要“批发计数”。“foreach”呼叫将为您计算计数

然后,控制器可以像这样将模型返回到视图

$data['wholesale'] = $this->your_model->get_wholesale_records();
$this->load->view('your_view', $data);
然后,视图中的前几行将减少为

<?php
foreach($wholesale as $record){ ?>
    //the rest as shown previously

//其余部分如前所示
$data['wholesale'] = $this->your_model->get_wholesale_records();
$this->load->view('your_view', $data);
<?php
foreach($wholesale as $record){ ?>
    //the rest as shown previously