PDA

View Full Version : Need a quick query


Jalrock
03 Dec 2002, 20:40
I am looking to set a variable ($memhealth) from data in the database. Something like this
$memhealth=$DB_site->query_first("SELECT `battle_health` FROM `user` WHERE userid=1");

but to pull from the member viewing the page not form userid 1

the above when put into a template as $memhealth only returns the word "Array" I need it to be the value stored in the database.

Any help appreciated.

Erwin
03 Dec 2002, 20:42
For any query looking for the user looking at the page, use this:

WHERE userid=$bbuserinfo[userid]

Jalrock
03 Dec 2002, 20:54
Thanks Erwin. That was easy. Now the next question. How do I re-do this query
$memhealth=$DB_site->query_first("SELECT `battle_health` FROM `user` WHERE userid=$bbuserinfo[userid]");
or what do I add to in that would return the results of of the field battle_health?

I have little or new clue when it comes to quering a database but I am trying to learn.

Erwin
03 Dec 2002, 21:08
Where are you using this query? Which PHP file?

You might as well join that query with an existing query in that file, so you save yourself 1 extra query, since there are many queries searching the user table in certain files that you can just add this to.

NTLDR
03 Dec 2002, 21:18
$memhealth[battle_health] is the variable the data is contained in.

Jalrock
03 Dec 2002, 21:27
This is a new php file. I am working on a hack and am stuck on this query.

Erwin
03 Dec 2002, 21:32
Okay, try this.

Make sure at the very top of the PHP file it says this:



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------




Then try this query:



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



And just put $battle_health anywhere in a template that is called from that PHP file. See if that helps.

Jalrock
03 Dec 2002, 21:37
Yea! Erwin it worked. Thanks guys.

Erwin
03 Dec 2002, 21:47
Glad it worked! :)