我在搜索脚本时遇到问题。问题是我想创建过滤器。过滤器是下拉菜单,我从此下拉菜单中输入数据到数组。我认为这是问题但是如何以不同的方式进入它。
或者如何将模型中的数据作为数组传递而不是obj。 (我认为这是对象)
我的搜索:
<?php echo form_open("otk/triedit", 'class="form-inline"'); ?>
<th scope="col"></th>
<th scope="col">ČÍSLO ZÁKAZKY</th>
<th scope="col"><?php echo form_dropdown(['class' => 'form-control', 'name' => 'p'], $pozicia); ?>POZÍCIA</th>
<th scope="col"><?php echo form_dropdown(['class' => 'form-control', 'name' => 's'], $stav); ?>STAV</th>
<th scope="col">PORADOVÉ ČÍSLO</th>
<th scope="col"><?php echo form_dropdown(['class' => 'form-control', 'name' => 'st'], $technologia); ?>TECHNOLÓGIA</th>
<th scope="col"><?php echo form_dropdown(['class' => 'form-control', 'name' => 'd'], $datum); ?>DÁTUM</th>
<th scope="col">DOKUMENT</th>
<th scope="col"><?php echo form_dropdown(['class' => 'form-control', 'name' => 'z'], $zariadenie); ?>ZARIADENIE</th>
<th scope="col">OPERÁTOR</th>
<th scope="col"><center></center></th>
<?php echo form_submit(['type' => 'submit', 'class' => 'btn btn-warning', 'value' => 'Hľadať']); ?>
<?php echo form_close(); ?>
我的控制器:
function triedit()
{
$this->load->model('base_model');
$udaje = array(
'hladat' => $this->input->post('p'),
'hladat' => $this->input->post('s'),
'hladat' => $this->input->post('st'),
'hladat' => $this->input->post('d'),
'hladat' => $this->input->post('z')
);
$keyword = $udaje;
$data['resulte'] = $this->base_model->triedit($keyword);
$this->load->view('base_triedit_view',$data);
}
我的模特:
function triedit($keyword)
{
$this->db->select('*');
$this->db->from('otk');
$this->db->like('ckod_otk',$keyword);
$this->db->join('technologia', 'technologia.id_technologia = otk.technologia_otk', 'left');
$this->db->join('zariadenie', 'zariadenie.id_zariadenie = otk.zariadenie_otk', 'left');
$this->db->join('zamestnanci', 'zamestnanci.id_zamestnanci = otk.operator_otk', 'left');
$this->db->join('stav', 'stav.id_stav = otk.stav_otk', 'left');
$query = $this->db->get();
return $query->num_rows();
}
我的观点预览:
<?php if(is_array($resulte)): ?>
<?php
foreach ($resulte as $row) {?>
<tr>
<td></td>
<td><?php echo $row->czakazky_otk; ?></td>
<td><?php echo $row->pozicia_otk; ?></td>
.....
<?php } ?>
<?php endif; ?>
答案 0 :(得分:0)
据我了解你的问题
form_dropdown
的数据选项格式始终位于array
,如果您使用form_dropdown
如果您希望您的模型应该将数据作为数组返回
这样做:
function triedit($keyword)
{
$this->db->select('*');
$this->db->from('otk');
$this->db->like('ckod_otk',$keyword);
$this->db->join('technologia', 'technologia.id_technologia = otk.technologia_otk', 'left');
$this->db->join('zariadenie', 'zariadenie.id_zariadenie = otk.zariadenie_otk', 'left');
$this->db->join('zamestnanci', 'zamestnanci.id_zamestnanci = otk.operator_otk', 'left');
$this->db->join('stav', 'stav.id_stav = otk.stav_otk', 'left');
$query = $this->db->get();
if ($query->num_rows() > 0 )
{
return $query->result_array();
}
}
视图中的更改:
<?php if(is_array($resulte)): ?>
<?php
foreach ($resulte as $row) {?>
<tr>
<td></td>
<td><?php echo $row['czakazky_otk']; ?></td>
<td><?php echo $row['pozicia_otk']; ?></td>
..............
<?php } ?>
<?php endif; ?>
更多信息:https://www.codeigniter.com/user_guide/database/results.html#result-arrays