Displaying 1st Entry

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
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Displaying 1st Entry

Post by iknownothing »

Hey guys,
I have a page where a single database entry is shown by changing the value of a drop-down menu. How would I display the first alphabetically ordered entry in the database without having to submit the dropdown menu form? The ID (auto-increment) field may not always be 1 as entries can be deleted, so I'm thinking that I should bypass the dropdown at first load but not sure how to word the sql query to display first entry in alphabetical order only.

Thanks
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Why not try something like:

Code: Select all

$result = MySQL_query("SELECT * FROM `whatever` ORDER BY `something` DESC");

$row=mysql_fetch_assoc($result);

// show the first row's thing here

do{

   //build the drop down options here

} while ($row=mysql_fetch_assoc($result));
edit: figured out what you meant and edited the post...
Last edited by Kieran Huggins on Sun Feb 11, 2007 5:40 am, edited 2 times in total.
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

no, i know how to order, and i know how display ALL entries, but I only want to display the very first alphabetical entry, eg AARDVARK.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

sorry - I was editing my post when you replied (I wish there was some ajax-powered new-post-notification in the edit window) - anyway, just wanted to "bump" the old thread.

You could also auto-select and submit the first entry with javascript.
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

I could have done that if my brain was on. Thanks.
Post Reply