SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Sort By Name

  1. #1
    SitePoint Zealot frosco's Avatar
    Join Date
    Jul 2003
    Location
    WA state
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sort By Name

    I need some help to change this code to sort by name ($name) instead of date. Any help much appreciated. This is the OS project mgmt system, Collabtive. Their forums are sparse.

    Code:
       /**
         * Lists all projects assigned to a given member ordered by due date ascending
         *
         * @param int $user Eindeutige Mitgliedsnummer
         * @param int $status Bearbeitungsstatus von Projekten (1 = offenes Projekt)
         * @return array $myprojekte Projekte des Mitglieds
         */
        function getMyProjects($user, $status = 1)
        {
            $user = mysql_real_escape_string($user);
            $status = mysql_real_escape_string($status);
            $user = (int) $user;
            $status = (int) $status;
    
            $myprojekte = array();
            $sel = mysql_query("SELECT projekt FROM projekte_assigned WHERE user = $user ORDER BY ID ASC");
    
            while ($projs = mysql_fetch_row($sel)) {
                $projekt = mysql_fetch_array(mysql_query("SELECT ID FROM projekte WHERE ID = $projs[0] AND status=$status"), MYSQL_ASSOC);
                if ($projekt) {
                    $project = $this->getProject($projekt["ID"]);
                    array_push($myprojekte, $project);
                }
            }
    
            if (!empty($myprojekte)) {
    			// Sort projects by due date ascending
    			$date = array();
    			foreach ($myprojekte as $key => $row) {
    				$date[$key] = $row['end'];
    			}
    			array_multisort($date, SORT_ASC, $myprojekte);
    			
                return $myprojekte;
            } else {
                return false;
            }
        }

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Try changing the column name you put in the $date array (I assumed the column name is 'name'):
    PHP Code:
    if (!empty($myprojekte)) {
      
    // Sort projects by due date ascending
      
    $date = array();
      foreach (
    $myprojekte as $key => $row) {
        
    // $date[$key] = $row['end'];  
        
    $date[$key] = $row['name'];  
      }
      
    array_multisort($dateSORT_ASC$myprojekte);
                
      return 
    $myprojekte;
    } else {
      return 
    false;


  3. #3
    SitePoint Zealot frosco's Avatar
    Join Date
    Jul 2003
    Location
    WA state
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This didn't work either - this coding is confusing me, it incorporates the Smarty templates which is a new world for this brain. I appreciate your help, it's possible I'm doing it wrong.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by frosco View Post
    This didn't work either
    Why? What happens? An error? The data shows not ordered?

    The code you posted is working ok?

    I don't know Smarty, so if it's a problem related to that, someone else will have to help out here.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2011
    Location
    zziapex.com
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?php
    class tempelate{
    function name(){
    return array( write you name here as array);
    }
    }
    $temp1=new template();
    $namen=$temp1->name();
    sort($name);
    echo "<table>";
    foreach($name as $keyvalue=>$page)
    {
    echo "<tr>";
    echo "<td>$page/td>";
    echo "</tr>";
    }
    echo "</table>";
    ?>


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
  •