Computing.Net > Forums > Database > PHP / MySQL Retrieve one record

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

PHP / MySQL Retrieve one record

Reply to Message Icon

Name: suspect52732
Date: August 20, 2007 at 19:50:28 Pacific
OS: XP
CPU/Ram: 2.4/512
Comment:

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'];


------------------


Any help would be greatly appreciated!



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: August 20, 2007 at 20:31:48 Pacific
Reply:

Um... What's wrong with replacing the echo line with:
$charity=$row['charity'];
? I only ask because my PHP experience is nonexistent.


0

Response Number 2
Name: suspect52732
Date: August 20, 2007 at 21:57:27 Pacific
Reply:

I tried every possible combination of that I can think of:

$charity=$row['charity'];
$charity=$row[charity];
$charity=$row["charity"];
$charity=$row['$charity'];
$charity=$row[$charity];
$charity=$row["$charity"];
$charity==$row['charity'];
$charity->$row['charity'];


But nothing seems to work. I know I am close though, because:

echo $row['charity'];

yields the right return. I just cant figure how to get it put into a variable.



0

Response Number 3
Name: mie2com
Date: September 25, 2007 at 16:13:05 Pacific
Reply:

Hi. I'm still learning MySQL, i'm not sure of this method of solution, but it should work:

$query = mysql_query("SELECT charity FROM `users` WHERE username=`$username`");
while($result = mysql_fetch_object($query)) {
$charity = $result->FIELD_NAME_HERE;
}
print($charity);


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Database Forum Home


Sponsored links

Ads by Google


Results for: PHP / MySQL Retrieve one record

ACCESS Record Merge www.computing.net/answers/dbase/access-record-merge/293.html

MySQL: Storage Engine/Field Type www.computing.net/answers/dbase/mysql-storage-enginefield-type/268.html

Php mysql www.computing.net/answers/dbase/php-mysql/464.html