Current location: Hot Scripts Forums » Programming Languages » PHP » sorting stuff from a mysql database in a - b - c


sorting stuff from a mysql database in a - b - c

Reply
  #1 (permalink)  
Old 03-18-05, 05:11 PM
Leipe_Po Leipe_Po is offline
New Member
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question sorting stuff from a mysql database in a - b - c

can somebody pleas tell me how to do that? whats the trick?
i need to order something on a alfabetical order like so:

a - b - c - d ect. ect

and when they click on the a the mysql database spits out all the titles that begin with an a and so on...

thanx alot,

Leipe_Po
Reply With Quote
  #2 (permalink)  
Old 03-18-05, 08:36 PM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hello,

You can use yourField LIKE 'x%' in your WHERE clause, where "x" replaces the character that the user has clicked on. e.g. to get all records whose "state" field begins with "s", use state LIKE 's%' .

Now you can pass an alphabetic letter via HTTP request (GET, POST, etc) when a user clicks on it and insert this letter into your SQL (i.e. "x" in the above example) to retrieve the corresponding data.

For more info on LIKE, I suggest that you consult with MySQL documentation:

http://dev.mysql.com/doc/mysql/en/st...functions.html

Hope this helps. =)
__________________
Blavv =|
Reply With Quote
  #3 (permalink)  
Old 03-19-05, 03:27 AM
Leipe_Po Leipe_Po is offline
New Member
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
i will try it out tonight, thanx for the info mate, will let you know if it works!
Reply With Quote
  #4 (permalink)  
Old 03-19-05, 09:24 AM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
or just in the query:

ORDER BY name

that will order words in the name field in alphabetical order! for example:

mysql_query("SELECT name, email, userid FROM users ORDER BY name");
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Form to update a MySQL database? Scoobler PHP 9 09-04-08 01:41 AM
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
Error while creating database (Errornumber 2002: "Can't connect to local MySQL server lylesback2 PHP 5 04-11-04 01:37 PM
Importing to a mysql database via php gulfan PHP 1 01-23-04 04:44 PM
how to import a png file from mysql database. rani PHP 1 01-16-04 03:34 AM


All times are GMT -5. The time now is 05:35 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.