-2
$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.

Shoaib Ali
  • 35
  • 1
  • 8

3 Answers3

1

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

Community
  • 1
  • 1
Frank
  • 664
  • 5
  • 15
  • You're still not giving me enough information to help you. Please look into it yourself and try to fix it. – Frank Apr 10 '15 at 11:10
  • this is my code ___> function getPreUnitOwner($unit) { $sql="SELECT SALUTATION,NAME FROM ownership_profile WHERE SID='".$_SESSION['socityid']."' and UNIT_ID='".$unit."'"; $result = mysql_query ($sql); $fullname=""; while ($result && $a = mysql_fetch_row ($result)){ $sal=$a[0]; $name=$a[1]; $fullname=$sal.' '.$name; } return $fullname; } – Shoaib Ali Apr 10 '15 at 11:22
0
order by id asc,
         name asc
juergen d
  • 201,996
  • 37
  • 293
  • 362
0

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
 )
RaMeSh
  • 3,330
  • 2
  • 19
  • 31