PHP Web Host - Quality Web Hosting For All PHP Applications $35/month $250/year (Unlimited) - $25/month - 200,000 impressions - Your Ad Could be Here - Click For Details
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
Defcon
Regular
Regular


Joined: Mar 10, 2005
Posts: 85

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

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: 7481
Location: Arizona

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

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.
View user's profile Send private message Visit poster's website
Defcon
Regular
Regular


Joined: Mar 10, 2005
Posts: 85

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

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
View user's profile Send private message Visit poster's website
montego
Site Admin


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

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

You are most welcome. Good luck! The learning process can be a ton of fun...
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic

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
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2008 by Raven
Proud to be listed at Lobo Links Web Directory

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::

:: fisubice Theme Recoded To 100% W3C CSS & HTML 4.01 Transitional Compliance by Raven and 64bitguy ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum