$sql="SELECT SALUTATION,NAME FROM ownership_profile WHERE SID='".$_SESSION['socityid']."' and UNIT_ID='".$unit."'";
How to ordery By ASC, 1st have to come Id with by acending order and second Names by Ascending Order.
$sql="SELECT SALUTATION,NAME FROM ownership_profile WHERE SID='".$_SESSION['socityid']."' and UNIT_ID='".$unit."'";
How to ordery By ASC, 1st have to come Id with by acending order and second Names by Ascending Order.
You aren't giving us much to work with. What is your table structure? I'm only guessing column names with the below.
$sql="SELECT SALUTATION,NAME FROM ownership_profile WHERE SID='".$_SESSION['socityid']."' and UNIT_ID='".$unit."' ORDER BY Id ASC, SecondName ASC";
Besides, a quick trip to Google/SO reveals this: SQL multiple column ordering
Try this example this is working fine for me,
I think this is a exact answer for your requirement.
Code:-
<?php
require_once("connect.php");
$sql="SELECT SALUTATION,NAME FROM ownership_profile WHERE SID='".$_SESSION['socityid']."' and UNIT_ID='".$unit."' order by NAME asc ";
$result = $con->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$array[] = $row['NAME'];
}
}
echo "After Sorting".'<pre>';
print_r($array);
echo '</pre>';
?>
sample output
Output:-
Array
(
[0] => abc
[1] => bca
[2] => cad
[3] => efg
[4] => fgh
)