Jump to content


Photo

Alphabetic sort and display


  • Please log in to reply
2 replies to this topic

#1 viper3two

viper3two
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 06 March 2006 - 02:41 PM

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

#2 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 06 March 2006 - 02:46 PM

Let mysql do that.

SELECT * FROM eelist WHERE HmDept='001' ORDER BY LstName

#3 viper3two

viper3two
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 06 March 2006 - 05:04 PM

[!--quoteo(post=352086:date=Mar 6 2006, 09:46 AM:name=wickning1)--][div class=\'quotetop\']QUOTE(wickning1 @ Mar 6 2006, 09:46 AM) View Post[/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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users