views:

62

answers:

1

Hello,

I have a rather (I think) easy problem to solve but being a PHP newbie, I can't seem to get the answer...

The query below, print a cloud of tags on my page. I'd like to add "ORDER BY TagID ASC" to this query so that the tags appeared according to their ID #, but I have no idea, where to put it (I didn't write that query, obviously).

<?php
   $tags = $data->select ( "Tag", "*" , NULL , 0 , 500 ) ;
   if ( ! empty ( $tags ) )
      foreach ( $tags as $tag ) :
         $counts = $data->count_record ( "Website_Tag" , array ( "TagID" => $tag["TagID"] ) ) ;

      if ( $counts > 20 )
         $font_size = $counts ;
      else
         $font_size = 11 ;

?>
<a style="font-size: <?php echo $font_size ?>px;" href="<?php echo base_url."coupons/".get_sef_url ( $tag["TagID"] , "Tag" ) ?>/"><?php echo $tag["TagName"] ?></a>

<?php
      endforeach ;
?>

Any help will be strongly appreciated? Thanks!

+2  A: 

You could try sort()

<?php
   $tags = $data->select ( "Tag", "*" , NULL , 0 , 500 ) ;
   if ( ! empty ( $tags ) )
      sort($tags); // sort here
      foreach ( $tags as $tag ) :
         $counts = $data->count_record ( "Website_Tag" , array ( "TagID" => $tag["TagID"] ) ) ;

      if ( $counts > 20 )
         $font_size = $counts ;
      else
         $font_size = 11 ;

?>
<a style="font-size: <?php echo $font_size ?>px;" href="<?php echo base_url."coupons/".get_sef_url ( $tag["TagID"] , "Tag" ) ?>/"><?php echo $tag["TagName"] ?></a>

<?php
      endforeach ;
?>
Phill Pafford
Thanks Phill, it worked perfectly!
Tioneb