reverse order

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cczernia
Forum Newbie
Posts: 20
Joined: Tue May 16, 2006 2:00 pm
Location: San Diego, CA

reverse order

Post by cczernia »

I have a query and am trying to reverse the results. I tried using "reverse_array" but it didn't work. Here is a quick example of what I have.

Code: Select all

$query = "SELECT wp_posts.post_title, wp_posts.post_date, wp_posts.post_excerpt, wp_posts.ID, wp_postmeta.meta_value
			   FROM wp_posts, wp_post2cat, wp_postmeta
			   WHERE wp_post2cat.category_id = '3'
			   AND wp_post2cat.post_id = wp_posts.ID
			   AND wp_postmeta.post_id = wp_posts.ID
			   ORDER BY wp_posts.post_date";

 $result = mysql_query($query);	
 	  
				  

if (!empty($result))
 {
	$numresults = mysql_num_rows($result);

	if ($numresults > 0)
	{
		for ($read_ctr=1; $read_ctr<=$numresults; $read_ctr++)
		{
		
		$row = mysql_fetch_array($result);
			
// input ITEM and VALUE
  
    $error="0";
    $title = $row['post_title'];
    $articleid = $row['ID'];
    $image = $row['meta_value'];
    $excerpt = $row['post_excerpt'];
I tried using the function revers_array on $result but it didn't work. Now, I'm not sure what kind of variable $result is. Anyone have any ideas on how to reverse the order of things either through PHP or SQL.

Thanks in advance.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Add an ASC or DESC to your ORDER BY in you sql.
Post Reply