Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

orderBy for multiple columns #18

Closed
beaucox opened this issue Jun 24, 2014 · 1 comment
Closed

orderBy for multiple columns #18

beaucox opened this issue Jun 24, 2014 · 1 comment

Comments

@beaucox
Copy link
Contributor

beaucox commented Jun 24, 2014

Hi -

I'm having trouble with the orderBy method. When I want to order by more than one column I can't seem to pass the columns in an array as shown in your GitHub docs. I have a feeling I'm missing the boat here... Can anyone help me?

This doesn't work:

$query = QB::table('movies')
  ->select(array('fs_name','name','release_date', 'rating','video_format','imdb_stars'));
$query->orderBy(array( 'release_date', 'DESC', 'sort_name', 'ASC'));
$queryObj = $query->getQuery();
echo $queryObj->getRawSql();
$result = $query->get();

Errors:

Warning: explode() expects parameter 2 to be string, array given in .../vendor/usmanhalalit/pixie/src/Pixie/QueryBuilder/Adapters/BaseAdapter.php on line 360
Warning: Invalid argument supplied for foreach() in .../vendor/usmanhalalit/pixie/src/Pixie/QueryBuilder/Adapters/BaseAdapter.php on line 362
Warning: implode(): Invalid arguments passed in .../vendor/usmanhalalit/pixie/src/Pixie/QueryBuilder/Adapters/BaseAdapter.php on line 368
...

The raw SQL is:

SELECT `fs_name`, `name`, `release_date`, `rating`, `video_format`, `imdb_stars` FROM `movies` ORDER BY ASC

This works:

$query = QB::table('movies')
  ->select(array('fs_name','name','release_date', 'rating','video_format','imdb_stars'));
$query->orderBy('release_date', 'DESC');
$query->orderBy('sort_name', 'ASC');
$queryObj = $query->getQuery();
echo $queryObj->getRawSql();
$result = $query->get();

The raw SQL is:

SELECT `fs_name`, `name`, `release_date`, `rating`, `video_format`, `imdb_stars` FROM `movies` ORDER BY `release_date` DESC,`sort_name` ASC
@usmanhalalit
Copy link
Owner

Hi,

If you want to use DESC then you've to put multiple orderBy like this

$query->orderBy('release_date', 'DESC')->orderBy('sort_name');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants