viper3two Posted March 6, 2006 Share Posted March 6, 2006 Hello, I am designing a webpage that reads a database in mysql and I am trying to sort and display the results. This example, I open my database, and pull it into an array. I want to search that array for HmDept="001", then sort the results by alpha (LstName). Can any body help me? Here is the code that I have so far:<?php$conn = mysql_connect("localhost", "root", "cpsint");mysql_select_db("employees",$conn);$sql = "SELECT * FROM eelist";$result = mysql_query($sql, $conn) or die(mysql_error());$display_block = "";if (mysql_num_rows($result) < 1) { //no record found $display_block .= "<p>No Record Found</p>"; } else { $display_block .= " <table cellpadding=3 cellspacing=2 border=1 width=98%> <tr> <th>First Name</th> <th>Last Name</th> <th>Title</th> <th>Picture</th> </tr>"; while ($newArray = mysql_fetch_array($result)) { $empnumber = $newArray['EmpNo']; $firstname = $newArray['FstName']; $lastname = $newArray['LstName']; $title = $newArray['Title']; $department = $newArray['HmDept']; $picfile = $newArray['PictureFile']; ///////THIS IS WHERE I NEED THE HELP :)/////// //////I WANT TO DISPLAY ONLY DEPARTMENT "001" /////// //////THEN SORT IT ALPHABETICALLY BY LastName////// if ($department == "001") { $display_block .= "<tr> <td align=center>$lastname <br> </td> <td align=center>$firstname <br> </td> <td align=center>$title <br> </td> <td align=center><img src=/EmployeeDirectory/database/$picfile> <br> </td> </tr>"; } }}?><html><head> <title>Administration</title></head><body> <p align="center"><a name="top" id="top"></a></p> <p align="center"><a name="top" id="top"></a></p> <p align="center"><font face="Arial" size="3">Administration</font></p> <?php echo $display_block; ?> </body></html>THANK YOU IN ADVANCE FOR THE HELP!!!!Tony Quote Link to comment Share on other sites More sharing options...
wickning1 Posted March 6, 2006 Share Posted March 6, 2006 Let mysql do that.SELECT * FROM eelist WHERE HmDept='001' ORDER BY LstName Quote Link to comment Share on other sites More sharing options...
viper3two Posted March 6, 2006 Author Share Posted March 6, 2006 [!--quoteo(post=352086:date=Mar 6 2006, 09:46 AM:name=wickning1)--][div class=\'quotetop\']QUOTE(wickning1 @ Mar 6 2006, 09:46 AM) [snapback]352086[/snapback][/div][div class=\'quotemain\'][!--quotec--]Let mysql do that.SELECT * FROM eelist WHERE HmDept='001' ORDER BY LstName[/quote]Thank you! I will give that a try and see what happens. Appreciate it!Tony Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.