Adrian
Adrian

Reputation: 2291

How to get the exact value from a column with php

I want to get the value from a column in a mysql table. The value from the mysql row is a simple number of 2 figures. (40) I tried:

$healthh = intval(mysql_query("SELECT health FROM users 
           WHERE username = ".quote_smart($username).""));

and in print_r($healthh); I get 33 instead of 40.

tried also

$healthh = mysql_query("SELECT health FROM users 
           WHERE username = ".quote_smart($username)."");

OUTPUT IS in this case Resource id #33

if i try like this:

$healthh = mysql_fetch_object(mysql_query("SELECT health FROM users 
           WHERE username = ".quote_smart($username).""));

I get the right value but not as an integer (a simple 2 figure number) OUTPUT: stdClass Object ( [health] => 40 )

Any ideas?

Upvotes: 0

Views: 770

Answers (1)

Jeribo
Jeribo

Reputation: 465

Use mysql_fetch_asoc()

$result = mysql_query("SELECT health FROM users 
       WHERE username = ".quote_smart($username)."");

$row = mysql_fetch_assoc($result);

$healthh = $row['health'];

Upvotes: 2

Related Questions