Codeigniter - 不显示任何数据

Codeigniter - Not showing any data on view

你能帮我解决这个问题吗?它没有出现在 table 我的视图中的任何数据上,这些数据是从数据库中获取的。感谢大家的协助。非常感谢。 这是我的代码:

控制器

public function index()
  {
    $this->load->helper('order_helper');
    $this->load->model('order_model');;
    $data["results"] = $this->order_model->getOrder('id', 'order_id', 'product', 'qty'); //check this parameter if it is correct

    $this->load->view('order_view', $data);
  }

型号

public function getOrder($id, $order_id, $product, $qty)
  {
    $rs = $this->db->get_where('order_items', array('id' => $id, 'order_id' => $order_id, 'product' => $product, 'qty' => $qty));
    return $rs->result_array();
  }

查看

<?php foreach ($results as $result) : ?>
        <tr>
          <td><?php echo $result['id']; ?></td>
          <td><?php echo $result['order_id']; ?></td>
          <td><?php echo $result['product']; ?></td>
          <td><?php echo $result['price']; ?></td>
          <td><?php echo $result['qty']; ?></td>
          <td><?php echo rating($result['price'], $result['total_price']); ?></td>
        </tr>
<?php endforeach; ?>

这是输出 - 它应该获取 table_name

上的数据

下面应该是这样的:

在你的控制器中你有这条线调用模型

 $data["results"] = $this->order_model->getOrder('id', 'order_id', 'product', 'qty'); 

您的模型需要一些参数

public function getOrder($id, $order_id, $product, $qty)
{
   $rs = $this->db->get_where('order_items', array('id' => $id, 'order_id' => $order_id, 'product' => $product, 'qty' => $qty));
   return $rs->result_array();
}

因此,您实际上正在做的是将以下内容传递到模型中。

$id = 'id', $order_id = 'order_id', $product = 'product', $qty = 'qty'

所以您传递的字符串值我猜在您的 order_items table 中不存在。 (他们没有)

你需要做的是传入实际values/strings。但是查看您的代码,我看不到这些值的来源。

您的目标是...

$data["results"] = $this->order_model->getOrder($id, $order_id, $product, $qty);

所以您需要问问自己,这些值(对于 $id、$order_id、$product 和 $qty)来自哪里?

但真正的问题是你为什么要这样做。

我怀疑你想做什么...

根据您的代码,您希望使用数据库中的值填充视图。所以你需要执行一个没有参数的Select(为了显示这个)。

您可以有一个名为 getOrders 的方法。

public function getOrders()
  {
    $rs = $this->db->get('order_items');
    return $rs->result_array();
  }

(是的,有几种方法可以编写上面的内容,但现在保持简单)

我强烈建议您阅读 CodeIgniter 用户指南并更加熟悉它。

希望对你有所帮助。

在您的模型中,尝试

public function getOrder($id, $order_id, $product, $qty)
{
    return $this->db->select('*')->from('order_items')->where(array('id' => $id, 'order_id' => $order_id, 'product' => $product, 'qty' => $qty))->get()->result_array();
}