hey there!
I'm trying to return a piece of data from a MySQL database and print it on the screen using the echo command.
I want this to appear on the screen:
GOLD : 'then the number of gold, say 1254 etc.'
So this is the command i use to display that
<?php echo "Gold: $gold" ?>
That will work fine, but it's getting the data assigned to the variable gold in a readable format thats the problem. I've tried doing something like this:
$gold_query = "SELECT gold
FROM player
WHERE username = $_COOKIE['user_name']";
$gold_result = mysql_query($gold_query);
$gold = mysql_result($gold_result);
why doesn't that work? The cookie has already been set by the way, i just need to work out how to pull the data out of the databse and assign it to the variable $gold.
Thanks in advance...
using php to return specific data from mysql
Moderator: General Moderators
-
shadow_blade47
- Forum Newbie
- Posts: 12
- Joined: Fri Nov 07, 2003 3:41 am
Code: Select all
<?php
$gold_query = "SELECT `gold`
FROM `player`
WHERE `username` = '{$_COOKIE['user_name']}' ";
$gold_result = mysql_fetch_array(mysql_query($gold_query));
$gold = $gold_result["gold"];
?>-
shadow_blade47
- Forum Newbie
- Posts: 12
- Joined: Fri Nov 07, 2003 3:41 am
I tried the following code:
But it didn't work, help would be appreciated. All i want to do is get the exact number stored in that cell of the database and print it to the screen, cheers.
Code: Select all
<?php
$gold_query = "SELECT `gold`
FROM `player`
WHERE `username` = '{$_COOKIE['user_name']}' ";
$gold_result = mysql_fetch_array(mysql_query($gold_query));
$gold = $gold_result["gold"];
?>You haven't told it that you are making a mysql query. Try this
Also, you don't need the $gold_result array as gold is the only item in the variable.
Code: Select all
<?php
$gold_query = mysql_query("SELECT `gold`
FROM `player`
WHERE `username` = '{$_COOKIE['user_name']}' ");
$gold_result = mysql_fetch_array($gold_query);
?>