Asanka Herath
Asanka Herath

Reputation: 1611

Print values in php array

I have a problem with this php code.

$q=$cn->exec('call get_count(1,@no_of_users)');
$res=$cn->query('select @no_of_users')->fetchAll();
echo "users".$res['@no_of_users']; 
print_r($res);

I get this output.

usersArray ( [0] => Array ( [@no_of_users] => 3 [0] => 3 ) )

Can anyone tell me how to echo value 3 only. That means I need to show the value of '@no_of_users'.

Upvotes: 1

Views: 67

Answers (2)

Irek Kubicki
Irek Kubicki

Reputation: 57

If $cn holds PDO instance use fetchColumn() instead of fetchAll()

Upvotes: 0

Abhik Chakraborty
Abhik Chakraborty

Reputation: 44844

You can do as

echo $res[0]["@no_of_users"];

Upvotes: 2

Related Questions