当我想从数据库中选择数据时遇到问题。
这是我的查询
SELECT J.id as id_job, J.title as job_title, J.companies_id, C.name as company_name,J.created_at, L.name as Location,CL.postal_code, CL.address
FROM jobs J
INNER JOIN bla1 C ON ( C.id = J.company_id )
INNER JOIN bla2 CL ON ( CL.id = J.company_location_id )
INNER JOIN bla3 L ON ( L.id = CL.location_id )
WHERE J.status =1
AND C.status =2
And CL.status = 1
AND L.status = 1
ORDER BY J.created_at DESC
LIMIT 0 , 30
这是该查询的结果var_dump()
["_result":protected]=>
array(15) {
[0]=>
array(8) {
["id_job"]=>
string(2) "27"
["job_title"]=>
string(10) "YUYUYUYUYU"
["company_id"]=>
string(1) "3"
["company_name"]=>
string(16) "voyage indonesia"
["created_at"]=>
string(19) "2012-10-03 09:35:37"
["Location"]=>
string(4) "Bali"
["postal_code"]=>
string(6) "989767"
["address"]=>
string(11) "dimana mana"
}
[1]=>
array(8) {
["id_job"]=>
string(2) "23"
["job_title"]=>
string(11) "OYEEEEAAHHH"
["company_id"]=>
string(1) "3"
["company_name"]=>
string(16) "voyage indonesia"
["created_at"]=>
string(19) "2012-09-28 09:06:54"
["Location"]=>
string(7) "Bandung"
["postal_code"]=>
NULL
["address"]=>
NULL
}
[2]=>
array(8) {
["id_job"]=>
string(2) "20"
["job_title"]=>
string(14) "TKPDKJKLADKSJA"
["company_id"]=>
string(1) "3"
["company_name"]=>
string(16) "voyage indonesia"
["created_at"]=>
string(19) "2012-09-20 09:24:50"
["Location"]=>
string(7) "Bandung"
["postal_code"]=>
NULL
["address"]=>
NULL
}
}
["_total_rows":protected]=>
int(3)
["_current_row":protected]=>
int(0)
["_as_object":protected]=>
bool(false)
我的目标:数组索引中的示例 8 像这样或比这个代码更好的东西
array(8) {
["id_job"]=>
string(2) "27"
["job_title"]=>
string(10) "YUYUYUYUYU"
["company_id"]=>
string(1) "3"
Array ( [companies] => array(1) {
["company_name"]=>
string(16) "voyage indonesia"
})
["created_at"]=>
string(19) "2012-10-03 09:35:37"
["Location"]=>
string(4) "Bali"
["postal_code"]=>
string(6) "989767"
["address"]=>
string(11) "dimana mana"
}
company_id 是关系表数据库表 bla1,我想在关系表中给出数组,所以我可以很容易地解析数据,有array('bla1' = > array('company_id',1));
什么建议吗?