我一直在努力查看代码的问题但我到目前为止,事情是我有一个数据库,当我尝试在html表上显示数据库信息时它是空白的,好像查询从来没有得到任何东西。
这是我的观点模型。
<body>
<form action="<?php echo base_url().'HomeController/index'; ?>" method="post">
<h1>Productos consolas de videojuegos</h1>
<table>
<thead style="background-color: orange">
<tr>
<th>ID</th>
<th>Producto</th>
<th>Proveedor</th>
<th>Descripción</th>
<th>Precio</th>
</tr>
</thead>
<tbody>
<?php if(!empty($info)){foreach($info as $inf){?>
<tr>
<td>
<input name="user id" value="<?php echo $inf->id;?>" />
</td>
<td>
<input name="nombre_producto" value="<?php echo $inf->nombre_producto;?>" />
</td>
<td>
<input name="proveedor" value="<?php echo $inf->nombre_proveedor;?>" />
</td>
<td>
<input name="descripción" value="<?php echo $inf->descripción;?>" />
</td>
<td>
<input name="precio" value="<?php echo $inf->precio;?>" />
</td>
</tr>
<?php }}?>
</tbody>
</table>
<div>
<input type="text" name="search" id="search" placeholder="Nombre de tu producto" />
<button type="submit" name="submit">Buscar</button>>
<p>Descripcion de la aplicacion: Hacer consultas en la tabla que incluye la base de datos de productos electronicos.<br></p>
<!-- <p>This is a second paragraph.</p>
-->
</div>
</form>
</body>
这是我的桌子型号
class HomeModel extends CI_Model{
public function getData(){
$query=$this->db->get('db_simbo');
return $query->result();
}
public function search_product($nombre_producto){
$this->db->select('*');
$this->db->from('db_simbo');
$this->db->like('nombre_producto',$nombre_producto);
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->result();
}
else{
return $query->result();
}
}
这是控制器
class HomeController extends CI_Controller{
public function index(){
$data = NULL;
$this->load->model('HomeModel',$data);
$config = array();
if($this->input->post() != ''){
$nombre_producto = $this->input->post('search');
if (isset($nombre_producto) and !empty($nombre_producto)) {
$data ['info'] = $this->HomeModel->search_product($nombre_producto);
}
}
else{
$data ['info'] = $this->HomeModel->getData();
}
$this->load->view('HomeView',$data);
}