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:
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?
