Jump to content
xisto Community

Retrieve 1

Recommended Posts


I am tring to get one single cell from a database. The primary key is username. I want to store the single cell in a variable called $charity. The code below seems to work. However, this outputs to the screen the answer. I want to store the answer in a variable.

$query="SELECT charity FROM `users` WHERE username='$username'";$result=mysql_query($query);$row = mysql_fetch_assoc($result);echo $row['charity'];

Notice from rvalkass:

Code needs to go into CODE tags. List of BBCodes.

Share this post

Link to post
Share on other sites

The reason is the last line: you echo out the result! Echo is used to output something to the browser, and is often used to output raw HTML code. If you want to store it as a variable, use the following code, in place of your current last line:


$charity = $row['charity'];

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.