Page 1 of 1

displaying sorted data

Posted: Sun Feb 02, 2003 5:48 pm
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

Posted: Sun Feb 02, 2003 11:02 pm
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)