Hello

I have a question about pulling a value from a mySQL DB.

Wondering how you pull just one value out of a list..

ex.
Table name is People

ID
1

FIRST NAME
Jim

LAST NAME
Boberson

PHONE
555-555-5555

AGE
99

How would I display just Jim Boberson's age on a page.. nothing else.

Also how would I insted of displaying his age on the page just set it to a variable called $jimbobage?

Thanks,
LTT

Recommended Answers

All 2 Replies

Member Avatar for diafol

This seems a little basic to be asking in a forum. Have you done any research yourself? If you looked at one of the most basic online tutorials, I bet you could get it to work without any help.

Just this once...

//create your connection string, $connection

$result = mysql_query("SELECT age FROM mytable WHERE id='1'", $connection);

$data = mysql_fetch_array($result);

$jimbobage = $data['age'];

echo $jimbobage;

//there are easier ways to do this, but the above will give you a 'repeatable' structure to follow for more complex queries where you only need to return one record (not one field!).

Thank you very much!

I did look around on the web a bit for the answer but kept finding ways to pull the whole row out.. I even tryed to find a answer on php.net.. Sorry for asking such a basic question ill try to look a little harder next time.

Thanks so much

-LTT

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.