Thread: Newbie Horror
View Single Post
Old 02-19-2008, 10:47 PM   #2 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Plugin/Addon

First and foremost, welcome to the community, Nathan! I hope you stick around and mingle!

As for your little problem, you will be wanting to add a WHERE clause to your SQL query. The WHERE clause is synonymous with -- I want only these rows! The way you would do that is, as you have an ID in your table, every member has a unique member ID -- or at least should have if that row is the primary key, as well as unique and, optionally, auto_increment.

Let's assume that the user's ID is stored in a session variable called id. You could output the ID in your PHP code like so:

php Code:
var_dump($_SESSION['id']);

Now, to add the WHERE clause, and only pull back the one record for the unique member ID, you would construct your query to look like the following, considering my member ID is 5:

sql Code:
SELECT
    gold
FROM
    users
WHERE
    id = 5

Thus, if the ID is in $_SESSION['id'] then I have everything I possibly need to build that query and execute it:

php Code:
$szSQL = sprintf("SELECT gold FROM users WHERE id = %d", $_SESSION['id']);

If the sprintf function is somewhat alien to you, and I understand it might be -- we've all come from the ground upwards! Then may I recommend a quick read of not only the documentation page on the wonderful sprintf, but also an article right here at TalkPHP:

I hope this helps you! Incidentally, is this for a game? Do we good folks get a sneak preview?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote