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.


   /**
     * 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;
        }
    }


Try changing the column name you put in the $date array (I assumed the column name is ‘name’):


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($date, SORT_ASC, $myprojekte);
			
  return $myprojekte;
} else {
  return false;
}

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. :slight_smile:

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.

<?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>”;
?>