SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    5
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sorting for loop values

    Hi,

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

    Code:
          <?
    	  $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

  2. #2
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,804
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Try this:

    PHP Code:

     $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.




    .

  3. #3
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •