1
votes

I have a select statement like this:

$select1 = $sql->select('table1');
$select1->columns('col1', 'col2', 'col3');

$select1->join('table2', 'table1.id = table2.id', array('col4', 'col5'));

$select1->join('table3', 'table2.id2 = table3.id2', array('col6', 'col7'));

My select statement shows columns in this order: col1, col2, col3, col4, col5, col6, col7.

I want to show columns in any other order, for example: col7, col6, col1, col2, col3, col4, col5.

How can I do that without changing my FROM statement and the order of the joins? I need something like specify the columns in just one $select1->columns() so I can set any columns order I want.

1
How would a different query change the way the data is presented on screen? Model and View are different things, change the presentation in your view, not in your model.Frank Heikens
Problem is that I'm doing a for each in the result and showing the columns in the same order as the result set. I know that's not very nice but that's why I need to find out a way to change columns order in the resultSetEdson Horacio Junior

1 Answers

2
votes

As I am not able to currently test this today, so just try this out for now -

$select1 = $sql->select('table1');
$select1->columns(array('col1', 'col2', 'col3'));
$select1->join('table2', 'table1.id = table2.id', array('col4', 'col5'));
$select1->join('table3', 'table2.id2 = table3.id2', array('col6', 'col7'));

Creating wrapper upon the above select statement.

$select_main = $sql->select();
$select_main->from(array('temp_table' => $select1));
$select_main->columns(array('col7', 'col6', 'col1', 'col2', 'col3', 'col4', 'col5'));

Now execute the $select_main and check the result.

This is just an idea that by creating a wrapper select to the result can help in changing the positions of the columns.

Will test the above code soon and let you know if any changes are required.

Good Luck!!!.