sort from msql and post to web page

General discussions related to php

Moderators: macek, egami, gesf

LTLhawk
New php-forum User
New php-forum User
Posts: 29
Joined: Fri Mar 07, 2003 4:17 pm

sort from msql and post to web page

Postby LTLhawk » Fri May 02, 2003 6:18 pm

the database I have is a set of 14 columns per id and i want to be able to sort the data based on any of the columns I choose. I am not sure how to do this so any help is appreciated. The database would be like this:


id name date time year place etc....
1 henry 3/2/03 2:30 2003 earth etc...
2 frank 4/5/99 1:40 2006 mars etc...
3 etc..

and so on...

I want to be able to sort by name or date and any of the fields and then be able to list (on a web page) all the info from that row.

thanks

User avatar
bezmond
Moderator
Moderator
Posts: 312
Joined: Sat Apr 05, 2003 4:33 am
Location: Mansfield, UK
Contact:

Postby bezmond » Fri May 02, 2003 11:17 pm

assuming I understand correctly:

say you have a file "table.php", if you wanted to be able to change the column to sort by, you'd need to have the page change to "table.php?sort=name" or "table.php?sort=date"

So we do this:

Code: Select all

mysql_connect("blah","blah","blah");
mysql_select_db("blah");
$query = "SELECT * FROM table SORT BY $sort ASC"; (or desc)
$result = mysql_query($query) or die(mysql_error());
***your table/listing stuff goes here***


Try that, hope it helps!!

Best Regards,
Andrew

LTLhawk
New php-forum User
New php-forum User
Posts: 29
Joined: Fri Mar 07, 2003 4:17 pm

Postby LTLhawk » Sat May 03, 2003 4:30 am

well I just tryed that and it works perfectly..thanks a lot man...
Last edited by LTLhawk on Sat May 03, 2003 4:58 am, edited 1 time in total.

User avatar
bezmond
Moderator
Moderator
Posts: 312
Joined: Sat Apr 05, 2003 4:33 am
Location: Mansfield, UK
Contact:

Postby bezmond » Sat May 03, 2003 4:30 am

no problem. :)

Andrew


Return to “PHP General”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest