nebchill26
06-26-2008, 09:11 PM
i just made this code but im having a problem sorting it from highest to lowest...i tried using ORDER BY but i still can't get it,can anyone help me out
here's my code:
<?php
$GetDepts = mysql_query("SELECT * FROM tblDepartment") or die ('MySQL SELECT Error: '.mysql_error());
while($DeparmentArray=mysql_fetch_array($GetDepts))
{
$Depts = $DeparmentArray['Department'];
$Counts = mysql_query("SELECT * FROM view_name where Department='$Depts'")
or die ('MySQL SELECT Error: '.mysql_error());
$CountedRows = mysql_num_rows($Counts);
//////THIS IS THE RESULT I WANT TO SORT
echo $CountedRows;
echo "<br \>";
}
?>
here's is the sample data in the database:
tblDepartment
ID | Department
1 | CSD
2 | HRD
3 | DCD
view_name
ID | DATE | Department | PCName
1 | JUNE | CSD | csd-1
2 | JUNE | CSD | csd-2
3 | JUNE | HRD | hrd-1
4 | JUNE | HRD | hrd-2
5 | JUNE | HRD | hrd-3
6 | JUNE | HRD | hrd-4
7 | JUNE | DCD | dcd-1
8 | JUNE | DCD | dcd-2
9 | JUNE | DCD | dcd-3
now i get the result by using the code and the database is this:
2
4
3
how can i make it to become
4
3
2
sort it depending on the data in the database,if it cannot be done,is there a work around it?tnx
here's my code:
<?php
$GetDepts = mysql_query("SELECT * FROM tblDepartment") or die ('MySQL SELECT Error: '.mysql_error());
while($DeparmentArray=mysql_fetch_array($GetDepts))
{
$Depts = $DeparmentArray['Department'];
$Counts = mysql_query("SELECT * FROM view_name where Department='$Depts'")
or die ('MySQL SELECT Error: '.mysql_error());
$CountedRows = mysql_num_rows($Counts);
//////THIS IS THE RESULT I WANT TO SORT
echo $CountedRows;
echo "<br \>";
}
?>
here's is the sample data in the database:
tblDepartment
ID | Department
1 | CSD
2 | HRD
3 | DCD
view_name
ID | DATE | Department | PCName
1 | JUNE | CSD | csd-1
2 | JUNE | CSD | csd-2
3 | JUNE | HRD | hrd-1
4 | JUNE | HRD | hrd-2
5 | JUNE | HRD | hrd-3
6 | JUNE | HRD | hrd-4
7 | JUNE | DCD | dcd-1
8 | JUNE | DCD | dcd-2
9 | JUNE | DCD | dcd-3
now i get the result by using the code and the database is this:
2
4
3
how can i make it to become
4
3
2
sort it depending on the data in the database,if it cannot be done,is there a work around it?tnx