Sorting for loop values

Hi,

Can somebody advise how can I sort the output of $v as we required (numbers ascending and descending)


      <?
	  $ii=1;
	  $sort_id=array(0,1,2,3,4,5,6,7,8,9);
	  
	  if ($_POST['sort'] == '1D')
	  {
	  // asort($sort_id);
	  }
	  
	  foreach ($sort_id as $v){
 	  $cooo = "SELECT count(number) AS total FROM doc WHERE time BETWEEN $date2 AND $date3";
	  $com = "$a"."$b"."$c"."$a8"."$d"."$e"."$f"."$g"."$h"."$i"."$j"."$k";
	  $com3 = "$a8"."$d"."$e"."$f";
	  $sql = mysql_query($cooo.$com)or die (mysql_error());

	  while($sd2=mysql_fetch_array($sql)) 
		{
	 ?>
        
        <tr valign="top">
          <td align="left" bordercolor="#999999" ><? echo "$ii"; ?></td>
          <td align="left" ><div align="center"><strong><? echo "$v"; ?></strong></div></td>


Thanks

Try this:



 $cooo = "
               SELECT count(number) AS total 
               FROM doc 
               WHERE time BETWEEN $date2 AND $date3 
               ORDER BY total
               LIMIT 0,10;
            ";

// if that does not work then the data may have to be sorted so include these lines:

  // your statement 
  $sql = mysql_query($cooo.$com)or die (mysql_error());

  // new temporary code
  $sd2 = mysql_fetch_array($sql);
  echo '<pre>';
    print_r($sd2);
  echo '</pre>';
  die();


Post the results and I will try and sort your data.

.

Two ways for sorting in your case:
1> using mysql: ORDER BY field ASC|DESC
2> if array is obtained as result then you can apply PHP’s array sorting functions like:
sort, asort, arsort, uasort, uksort etc.