Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> MySQL
Author Message
Defcon
Regular
Regular



Joined: Mar 10, 2005
Posts: 90

PostPosted: Fri Jul 06, 2007 3:38 pm Reply with quote

Image

Hye all!! I got some basic question about SQL + PHP. I would like to know with PHP to call last row of ID? I mean like image above, i would like to view only that 1009 as output on my website and NOT all of from 1,1007,1005,1006,1008 & 1009. I alread try with

Code:


$id = $row['id'];
echo "Last ID is - ".$id."";


But that will list all of that ID in the row, so can someone tell me what a exactly "$" i have to use.

If u dont mind i also need to know any referrer URL for SQL newbies where i can know & understand any basic SQL library key/etc.

thanxs
 
View user's profile Send private message Visit poster's website
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Fri Jul 06, 2007 5:54 pm Reply with quote

Assuming that the user_id is of type "Auto Increment", you can be assured that they are in numerical sequence. So, this would work:

Code:


SELECT user_id FROM site_users ORDER BY user_id DESC LIMIT 1;


It is also possible that the following will work:

Code:


SELECT max(user_id) AS user_id FROM site_users;


But, I am not where I can test that last one. (I cannot remember if it needed a GROUP BY clause on it.

Regarding learning SQL, I believe that I already gave you a good book? Other than that, I really just like mySQL's on-line command reference.

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
Defcon







PostPosted: Sat Jul 07, 2007 1:09 am Reply with quote

montego wrote:
Assuming that the user_id is of type "Auto Increment", you can be assured that they are in numerical sequence. So, this would work:

Code:


SELECT user_id FROM site_users ORDER BY user_id DESC LIMIT 1;


It is also possible that the following will work:

Code:


SELECT max(user_id) AS user_id FROM site_users;


But, I am not where I can test that last one. (I cannot remember if it needed a GROUP BY clause on it.

Regarding learning SQL, I believe that I already gave you a good book? Other than that, I really just like mySQL's on-line command reference.


Hye again montego, yes u right that book is really a good one:p i really appreciate it. I just buy that book a couple weeks ago but still not complete to read n try all of exercise there:p But i will/must read n do any exercise to make sure i can become a good programmer. Whatever, thanxs for your code so now i already get that "keyword" i really appreciate it. Dont know how i can express my big appreciate on you since u introduce to me that book. But sometimes, although i already got a good book maybe i still got something to ask here wish all of my friends can help me here Smile Once i already be a good programmer of course i will help them like u help me. Thanxs dude:p
 
montego







PostPosted: Sat Jul 07, 2007 7:23 am Reply with quote

You are most welcome. Good luck! The learning process can be a ton of fun...
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> MySQL

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©