views:

28

answers:

2

I'm running a query that looks like this:

 $results = $DB2->query("SELECT COUNT(*) FROM auth_user as count WHERE email='" . $DB2->escape_str($email) . "';");

It's returning an object that looks like this:

DB_Cache Object
(
[result] => Array
    (
        [0] => Array
            (
                [COUNT(*)] => 0
            )

    )

[row] => Array
    (
        [COUNT(*)] => 0 // I WANT YOU!
    )

[num_rows] => 1
[q_count] => 1
[fields] => Array
    (
    )

)

I am trying to access the [count] array value using this:

$results->row['count'];

It's not returning anything. Any ideas what I'm doing wrong?

+1  A: 

Try this:

$results->row["COUNT(*)"]

The value between [] indicates the key of the array. You have to use exactly that key in order to access the array's value.

Simon
Thanks Simon! I'd been looking at the code too long :)
Phil
no problem ;) ...
Simon
+3  A: 

Change your SQL statement from COUNT(*) to COUNT(*) AS count

Kerry
Thanks a ton! Totally missed that.
Phil
Not a problem! :)
Kerry