在两张表里搜寻关键字,把符合关键字所对应的id查询出来
$keyword = "XX"; //关键字$sql1= "select id from table1 where title like "%$keyword%";$result1 = $this->db->getAll($sql1); //sql执行后返回的id数组foreach($result1a as $k=>$v){ $result1[$k]['flat'] = 1; //给一个标识, 让我知道这是从table1里查出来的}$sql2= "select id from table2 where title like "%$keyword%";$result2 = $this->db->getAll($sql2);foreach($result2a as $k=>$v){ $result2[$k]['flat'] = 2;} $result = array_merge_recursive($result1, $result2);
遇到什么问题??
1、你的$result1a,$result1b都是空,循环没什么意义,估计打错了
2、循环体貌似也没什么用
请把问题描述清楚
遇到什么问题??
1、你的$result1a,$result1b都是空,循环没什么意义,估计打错了
2、循环体貌似也没什么用
请把问题描述清楚
$keyword = "XX"; //关键字 $sql1= "select id from table1 where title like "%$keyword%";$result1 = $this->db->getAll($sql1); //sql执行后返回的id数组foreach($result1 as $k=>$v){ $result1[$k]['flat'] = 1; //给一个标识, 让我知道这是从table1里查出来的} $sql2= "select id from table2 where title like "%$keyword%";$result2 = $this->db->getAll($sql2);foreach($result2 as $k=>$v){ $result2[$k]['flat'] = 2;} $result = array_merge_recursive($result1, $result2);
$sql1= "select id,1 as flat from table1 where title like '%$keyword%' union all select id,2 as flat from table2 where title like '%$keyword%'";