RSprinkel Posted September 7, 2006 Share Posted September 7, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/20034-help-needed/ Share on other sites More sharing options...
wildteen88 Posted September 7, 2006 Share Posted September 7, 2006 Use this as the query:SELECT * FROM users_table ORDER BY user_id_column DESC LIMIT 1Should select the last row from the database Quote Link to comment https://forums.phpfreaks.com/topic/20034-help-needed/#findComment-87885 Share on other sites More sharing options...
obsidian Posted September 7, 2006 Share Posted September 7, 2006 [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 1Should select the last row from the database[/quote]assuming your table is set up with an auto-incrementing primary key ;-) lolyou 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! Quote Link to comment https://forums.phpfreaks.com/topic/20034-help-needed/#findComment-87976 Share on other sites More sharing options...
R_P Posted September 7, 2006 Share Posted September 7, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/20034-help-needed/#findComment-87989 Share on other sites More sharing options...
wildteen88 Posted September 7, 2006 Share Posted September 7, 2006 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 Link to comment https://forums.phpfreaks.com/topic/20034-help-needed/#findComment-87990 Share on other sites More sharing options...
obsidian Posted September 8, 2006 Share Posted September 8, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/20034-help-needed/#findComment-88318 Share on other sites More sharing options...
HuggieBear Posted September 8, 2006 Share Posted September 8, 2006 Oracle has it too... 'rownumber' it's a psuedocolumn.RegardsRich Quote Link to comment https://forums.phpfreaks.com/topic/20034-help-needed/#findComment-88323 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.