showing links alphabatically ordered

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
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

showing links alphabatically ordered

Post by crazytopu »

A quick question:

My admin user (who is a completely non-tech person) is now able to insert a new link and a number of sublink under the link. My management now wants that insead of order by the sublink with sublink_id, i rather arrange their order alphabatically.

I wonder is there any php built-in function that i can use?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

You are pulling these links from a database?

Just modify your query a bit..

Code: Select all

.. ORDER BY `sublink_id`
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

yes, i m drawing all my links and sublinks from the database. The thing is, so far i did order their sublink_id. So, i wrote something like

Code: Select all

order by sublink_id desc;

That way, the most recent sublink were appearing at the bottom of the sublink list. But management wants that they dont want the most recent ones go at the bottom of the list, rather they want that the list is arranged alphabatically. Which i understand can't be done using a sql query alone.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

.. ORDER BY `sublink_id` DESC
or

Code: Select all

.. ORDER BY `sublink_id` ASC
To reverse their order
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

do u understand what I am trying to say? I want to arrange all those sublinks (their title to be more precise, upon clicking which u get the body of that sublink in a separate page).

Now, i want this sublink title to be displayed alphatebatically. So, here, their ID r not playing a big role at all. Coz, i will have to fetch their title first and then arrange their order alphatically, which i understand cant be done with SQL alone.

I need a function ....is there any built-in one?
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

why can't you order by the sublink_title in sql? Just order by the sublink_title then.

Code: Select all

.. ORDER BY `sublink_title` DESC
or

Code: Select all

.. ORDER BY `sublink_title` asc
if this isn't what you want try create a small diagram for what you want.
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

Aha! thanks a lot. Indeed, I was looking for this exact solution. Stupid of me that I didnot realise that I could easily sort out any column in the database with the order by clause.

Yah, it did work :)


cheers,
Topu
Post Reply