Jump to content

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/4210-alphabetic-sort-and-display/
Share on other sites

[!--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
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.