This is the output format that i want:
array( 'db' => 'sta.name', 'dt' => 0, 'field' => 'name' )
array( 'db' => 'rec.date_received', 'dt' => 1, 'field' => 'date_received' ) .. and so on
This is my code:
$columns = array();
$kolomn = array('name', 'date_received', 'job_status', 'jobno', 'company_name', 'suburb', 'item', 'comment', 'location', 'warehouse_name', 'created', 'state');
$alias = array('rec', 'com', 'sta', 'loc', 'pro');
$joinQuery = "FROM tableA AS {$alias[0]} LEFT JOIN tableB AS {$alias[1]} ON ({$alias[0]}.company_id = {$alias[1]}.company_id) JOIN tableC AS {$alias[2]} ON ({$alias[0]}.staff_id = {$alias[2]}.staff_id) JOIN tableD AS {$alias[3]} ON ({$alias[0]}.warehouse_id = {$alias[3]}.warehouse_id) LEFT JOIN tableE AS {$alias[4]} ON ({$alias[0]}.jobno = {$alias[4]}.jobno)";
foreach ($kolomn as $key => $value) {
$columns[] = array( 'db' => $alias[0].$value, 'dt' => $key, 'field' => $value );
}
Obviously $alias[0] only give me “rec” everytime.
How to make it changing corresponding to the table where the column belong?
For instance:
column “name” belongs to tableC .. so ‘db’ => sta.name, ‘dt’ => 0 supposed to be ‘db’ => $alias[2].$value, ‘dt’ => $key
column “date_received” belongs to tableA .. so ‘db’ => rec.date_received, ‘dt’ => 1 supposed to be ‘db’ => $alias[0].$value, ‘dt’ => $key
column “job_status” belongs to tableE .. so ‘db’ => pro.job_status, ‘dt’ => 3 supposed to be ‘db’ => $alias[4].$value, ‘dt’ => $key