displaying sorted data

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
Little Spy
Forum Commoner
Posts: 31
Joined: Thu Oct 10, 2002 8:18 pm
Contact:

displaying sorted data

Post by Little Spy »

Does anyone know of a good method for sorting things by letter. I have a script with many reviews of different shows in it. I would like to be able to sort them a-g, h-j, k-m (you get the picture)

i came up with this method

Code: Select all

$query = reg_query("SELECT * FROM reviews ORDER BY name ASC");
   // Output The List
   while ($data = fetcho_query($query)) {
      if (substr($dataї'name'],0,1) == strtoupper($split))  break;
      // Make overall rating
      $rating = round(($dataї'rating_animation'] + $dataї'rating_characters'] + $dataї'rating_music'] + $dataї'rating_plot'] + $dataї'rating_sound'] + $dataї'rating_voiceacting']) / 6, 1);
      $date = date("n/j/Y", $dataї'revid']);
      $search = array('<LISTBIT: Name>', '<LISTBIT: Genre>', '<LISTBIT: Type>', '<LISTBIT: Date>', '<LISTBIT: Rating>', '<LISTBIT: ID>');
      $replace = array($data&#1111;'name'], $data&#1111;'genre'], $data&#1111;'type'], $date, $rating, $data&#1111;'revid']);
      $list_reviews .= str_replace($search, $replace, stripslashes($keybase&#1111;'review_listbit']));
   &#125;
$split is the letter to stop displaying data at and this works, but i have not the slightest how to do something that would let me say start at "C" and stop at "S". If there is no way to do this through variables, I would settle for hard coding the sorting methods in to just being a-g, h-k strictly. If there is a way to do this through a query please share.

Matt
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

you could just limit that in the query?

SELECT col1,col2,col3,col4 FROM mytable WHERE col2 > 'K' AND col2 < 'M' ORDER BY col2

(BTW, never use SELECT * unless you are in fact using every single column)
Post Reply