query doesnt sort results

[php]<?php

			global $wpdb, $post;
			$results = $wpdb->get_results(
					"
					SELECT * FROM $wpdb->posts
					WHERE post_title LIKE '$mo%'
					AND post_type = 'movies'
					AND post_status = 'publish';
					"
			 );
		
		sort( $results );

			 if ( $results ) {

				foreach ( $results as $post ) {

					setup_postdata ( $post ); 

		?> [/php]

I have no Idea why this doesn’t sort my results out alphabetically.

any help appreciated

sort doesn’t know how it should sort the results, if you look at what data is in results then how on earth should the sort function know what you want to sort by?

Add a sort (order by) condition to your query. Much faster to sort in sql when getting the results anyway

I have tried it your way also but I am obviously doing it wrong as I get no results.

What did you try?

SORT BY post_title DESC

Its ORDER BY.

[php]<?php

			global $wpdb, $post;
			$results = $wpdb->get_results(
					"
					SELECT * FROM $wpdb->posts
					WHERE post_title LIKE '$mo%'
					AND post_type = 'movies'
					AND post_status = 'publish'
					ORDER BY post_title ASC;
					"
			 );
		
		sort( $results );

			 if ( $results ) {

				foreach ( $results as $post ) {

					setup_postdata ( $post ); 

		?> [/php]

so this will work ? right ?

Yes that should work fine.

Sponsor our Newsletter | Privacy Policy | Terms of Service