Jump to content

Alphabetical Ordering from a database


Travist6983

Recommended Posts

I am trying to figure out how to alphabetize a client list that draws from my data base here is the code i am playing with if any one could help nudge me ;) in the right direction i would be forever grateful

 

 $query = "SELECT id, firstName, email, lastName, LEFT(lastName, 1) AS first_char FROM userAccounts WHERE UPPER(LEFT(lastName, 1)) BETWEEN 'A' AND 'Z' OR LEFT(lastName, 1) BETWEEN '0' AND '9' ORDER BY lastName WHERE assignedAgent = ".$_SESSION['agent']['agentID'];
				    		$clients = mysql_query($query);
				    		$current_char = '';
				    		if( mysql_num_rows($clients) > 0 )
				    		{
					    		while( $client = mysql_fetch_array($clients) )
					    		{
  									  if ($client['first_char'] != $current_char) {
    							      $current_char = $client['first_char'];
       							      echo '<br />' . strtoupper($current_char) . '<br />-----<br />';
  								  }
						    		echo "<tr>";
						    		echo "	<td>".$current_char['lastName']."</td>";
						    		echo "	<td>".$client['firstName']."</td>";
									echo "	<td>".$client['email']."</td>";
									echo "	<td>".$client['group']."</td>";
						    		echo "	<td align='center'><a href=\"editClient.php?clientID=".$client['id']."\">Edit Client</a></td>";		
									//echo "	<td><a href='clientWebforms.php?clientID=".$client['id']."'>View Webforms</a></td>";
						    		echo "</tr>";	
					    		}
				    		}
				    		else
				    			echo "<tr><td colspan='3' align='center'><font color='red'>You have no clients assigned!  To have your clients assigned to you search for them using the 'Find Clients' button on the left navigation bar.</font></td>";
				    	

 

Thanks for any and all comments

 

Travis

Link to comment
Share on other sites

I kinda thought that was what was causing the problem but how do you correctly write the statement i am not really a php programmer but figured i would give this a try to eliminate some work from my co-workers.

 

basically what i was trying to do was the order the clients alphabetically by last name instead of by there database ID  this was the old statement that i am trying to edit

$query = "SELECT lastName, id, firstName, email FROM userAccounts WHERE assignedAgent = ".$_SESSION['agent']['agentID'];

 

and you obviously can see the new statement that i created from reading a bunch of forum posts.

 

Any help would be greatly appreciated

 

thanks

 

Travis

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.