Page 1 of 1

SQL Statement in PHP

Posted: Sun Mar 15, 2009 7:40 pm
by res_123
Hello Everybody,

I have the following MySql statement in my php form:

Code: Select all

 
$sql = "SELECT * FROM `forum_sub_cats` WHERE `cid`='".$row2['id']."' AND `admin` < ".$row['admin']."+1";
 
I would like the above in ascending order i.e. Order By Asc.

Thanks

Re: SQL Statement in PHP

Posted: Sun Mar 15, 2009 7:56 pm
by socket1
Well you have to know the column you want to sort it by.

Then append ORDER BY columnname
to the end of your MySQL syntax to sort from
1
2
3
4


or append ORDER BY columnname DESC
to get
4
3
2
1

or to order by multiple columns do ORDER BY columnname, column2name


Take a look here .... http://dev.mysql.com/doc/refman/5.0/en/ ... -rows.html

Re: SQL Statement in PHP

Posted: Sun Mar 15, 2009 8:06 pm
by res_123
socket1 wrote:Well you have to know the column you want to sort it by.

Then append ORDER BY columnname
to the end of your MySQL syntax to sort from
1
2
3
4


or append ORDER BY columnname DESC
to get
4
3
2
1

or to order by multiple columns do ORDER BY columnname, column2name


Take a look here .... http://dev.mysql.com/doc/refman/5.0/en/ ... -rows.html
Thanks socket for the advice.

This is what I did and it worked:

Code: Select all

 
$sql2 = "SELECT * FROM `forum_sub_cats` WHERE `cid`='".$row2['id']."' AND `admin` < ".$row['admin']."+1 ORDER BY `desc` ASC";