SQL Statement in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
res_123
Forum Newbie
Posts: 16
Joined: Fri Mar 13, 2009 6:47 pm

SQL Statement in PHP

Post 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
socket1
Forum Commoner
Posts: 82
Joined: Mon Dec 08, 2008 7:40 pm
Location: Shokan, New York

Re: SQL Statement in PHP

Post 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
res_123
Forum Newbie
Posts: 16
Joined: Fri Mar 13, 2009 6:47 pm

Re: SQL Statement in PHP

Post 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";
 
Post Reply