Hi all! I am still new at PHP and mysql and am having a little difficult time figuring out how to get my "Trainee Name" link to switch my info list from ascending to descending order and vice versa. Right now, you will see it defaults to ASC. Any help would be greatly appreciated. Thanks!

if (((!$keywords)) && ($_POST["submit"] != 'Edit Trainee') && ($_POST["submit"] != 'Add Trainee') && ($_GET["action"] != 'edit') && ($_GET["action"] != 'add')) {

      $query_trainees = "SELECT * FROM tdb_trainees ORDER BY tdb_trainees.last_name ASC";
   
	//echo $query_trainees."<br>";    
	$result_trainees = mysql_db_query($dbname, $query_trainees);	
	while ($r = mysql_fetch_array($result_trainees)) {
		   $trainee_id = $r["trainee_id"];
		   $last_name = $r["last_name"];
		   $first_name = $r["first_name"];
		   $producer_id = $r["producer_id"]; 
		   $phone1 = $r["phone1"];		  
		   $query_producer = "SELECT name FROM tdb_producers WHERE producer_id='".$producer_id."'";
		   $result_producer = mysql_db_query($dbname, $query_producer);
		   list($producer_name) = mysql_fetch_array($result_producer);
		   if (strlen($producer_name) > 30) {
		   	 $producer_name = substr($producer_name, 0, 30)."...";
		   }	   
	  	   $trainees_list_output .= '
			 <tr>
	          <td valign="top"><br><a href="/training/trainees.php?action=edit&trainee_id='.$trainee_id.'">'.$last_name.', '.$first_name.'</a></td>
	          <td valign="top"><br>'.$producer_name.'</td>
	          <td valign="top"><br>'.$phone1.'</td>
			</tr>';
	}
	
	echo '<table width="580" align="right" border="0" cellspacing="0" cellpadding="0">
	        <tr>
	          <td colspan="3">
			  <i>NOTE: Click the trainee name to edit/delete a trainee, or <a style="text-decoration:underline" href="/training/trainees.php?action=add&pid='.$producer_id.'">Add a New Trainee</a> here.</i><br>&nbsp;</td>
	        </tr>
	        <tr>
	          <td width="210" valign="top"><u>Trainee Name</u>:</td>
	          <td width="260" valign="top"><u>Company</u>:</td>
	          <td width="110" valign="top"><u>Phone</u>:</td>
			</tr>
			'.$trainees_list_output.'
		  </table>';
	
}
Member Avatar for diafol

DESC?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.