下面,如果我的代码用于数据表的列搜索以及完整搜索,
$columns = array(0 => 'ship_id' ,
1 => 'sr',
2 => 'ce',
3 => 'sto',
4 => 'supply' ,
5 => 'part',
6 => 'description',
7 => 'quantity',
8 => 'date',
9 => 'shipn',
10 => 'ship',
11 => 'transport',
12 => 'docket',
13 => 'delivery');
if(isset($searchValue) && $searchValue != '')
{
$searchingAll = array();
for($i=0; $i<count($columns); $i++) //Loop search in all defined columns
{
$searchingAll = $this->db->or_like($columns[$i], $searchValue);
$searchingColumns = NULL;
}
}
else if($this->input->post('columns[1][search][value]', TRUE) != '')
{
for($i=0; $i<count($columns); $i++) //Loop search in all defined columns
{
$searchingAll = NULL;
$searchingColumns = $this->db->or_like($columns[1], $this->input->post('columns[1][search][value]', TRUE));
}
}
else
{
$searchingAll = NULL;
$searchingColumns = NULL;
}
第一个IF条件将搜索完整的数据表,然后,否则-如果将搜索单个列,
我的数据表中有12列,所以我需要循环12次,否则,如果有条件,
目前在上面的代码中,我仅显示第1列,但是我需要检查所有12列是否在任何列搜索中输入了某些内容,然后它将转到else-if条件的循环中,
如何在else-if条件下检查所有12列?
谢谢,
最佳答案
您没有使用在$i
中定义的else if
。
使用此代替:
$columns = array(0 => 'ship_id' ,
1 => 'sr',
2 => 'ce',
3 => 'sto',
4 => 'supply' ,
5 => 'part',
6 => 'description',
7 => 'quantity',
8 => 'date',
9 => 'shipn',
10 => 'ship',
11 => 'transport',
12 => 'docket',
13 => 'delivery');
if(isset($searchValue) && $searchValue != '')
{
$searchingAll = array();
for($i=0; $i<count($columns); $i++) //Loop search in all defined columns
{
$searchingAll = $this->db->or_like($columns[$i], $searchValue);
$searchingColumns = NULL;
}
}
else if($this->input->post('columns[1][search][value]', TRUE) != '')
{
for($i=0; $i<count($columns); $i++) //Loop search in all defined columns
{
$searchingAll = NULL;
$searchingColumns = $this->db->or_like($columns[$i], $this->input->post('columns['.$i.'][search][value]', TRUE));
}
}
else
{
$searchingAll = NULL;
$searchingColumns = NULL;
}