从数据库和其他数据库中选择相关的数据


Select data from a database and other database related to the

//$find = $this->input->post('val');
$find = 'hello';

例如,我有两个数据库data1 &data2data1

ROW1: 111 | 11 | 1
ROW2: 222 | 22 | 2
ROW3: 333 | 33 | 3
ROW4: 444 | 44 | 4

,在数据库data2中为:

ROW1: hi | 234 | 978
ROW2: 4312 | hello | 122

它们在<table></table>中显示(select * from ...)为:

ROW1: 111 | 222 | 333 | 444 | hi | 4312
ROW2: 11 | 22 | 33 | 44 | 234 | hello//我想只显示这个ROW2,因为这个ROW有值hello
ROW3: 1 | 2 | 3 | 4 | 978 | 122

我的尝试是这样的:

//$find = $this->input->post('val');
$find = 'hello';
$this->db->query("SELECT * FROM array('data1','data2') WHERE name LIKE '%$find%' OR number LIKE '%$find%'")

如何在两个数据库中使用php完成这项工作?(如果没有codeigniter怎么能没有codeigniter?)

你到底想要什么?namenumber字段在哪个表中?我想你需要类似的:

(SELECT * FROM data1 WHERE name LIKE "%$find%") UNION (SELECT * FROM data2 WHERE number LIKE "%$find$")

您可以查看CI的Active Record类