Jump to content

Archived

This topic is now archived and is closed to further replies.

RSprinkel

Help needed

Recommended Posts

Hi all,

I am trying to figure out a code to pull the newest member out my user database.

I am using a MySQL db.

Any help would be greatly appreciated.

Thanks much in advance.

Share this post


Link to post
Share on other sites
Use this as the query:
SELECT * FROM users_table ORDER BY user_id_column DESC LIMIT 1
Should select the last row from the database

Share this post


Link to post
Share on other sites
[quote author=wildteen88 link=topic=107255.msg430034#msg430034 date=1157653074]
Use this as the query:
SELECT * FROM users_table ORDER BY user_id_column DESC LIMIT 1
Should select the last row from the database
[/quote]

assuming your table is set up with an auto-incrementing primary key ;-) lol

you really will have to give us a little more information than that. if you have an id column that is an auto-increment field, that's probably your best bet. however, if you have a date column that records the membership date, something like that could be used as well. if you don't have any sort of ordering available to you, i'm afraid you might be stuck!

Share this post


Link to post
Share on other sites
If you do not have an auto-incrementing primary key or date column (which would be bad practice), getting info will be much more process heavy. Since MySQL by default orders data by date inserted (ASC), I guess you could (theoretically, mind you) select ALL the usernames into an array, and then use array_pop() to get the last username.

Just an idea.

Share this post


Link to post
Share on other sites
Well ideally any table should have an auto incrementing column, which will be the primary key. Howev i was pressed for time when I was posting, so I just rushed the post abit.

Share this post


Link to post
Share on other sites
[quote author=wildteen88 link=topic=107255.msg430154#msg430154 date=1157662704]
Well ideally any table should have an auto incrementing column, which will be the primary key. Howev i was pressed for time when I was posting, so I just rushed the post abit.
[/quote]
i figured as much ;) so i thought i'd clarify for you...

one other thought... i'm not sure how mysql handles this, but in postgresql, you have a pid that is generated as a bookmark for the server, and you never even see it (even through phpmyadmin) unless you specifically query for it. i suppose if mysql has something similar, you could order by that as well.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.