当我想从数据库中选择数据时,我遇到了问题。
这是我的查询
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));
有什么建议吗?
答案 0 :(得分:1)
我认为这就是你想要的。
array[$row_id] = $row;
答案 1 :(得分:1)
我没有看到您可以从SQL查询中获取嵌套数组。 数据库查询提供的行和列没有进一步的子结构。
您当然可以通过编程方式执行此操作,只需将具有作业和位置的表作为数组,然后从中生成所需的嵌套列表。但是,你失去了加入的力量,需要将它嵌入你的代码中。