简体   繁体   中英

MYSQL Query Error (Result Array)

I have this result

Furni Count: Array

My code is

$query2 = mysql_query(
                "SELECT COUNT(DISTINCT id) FROM items
                 WHERE base_item='" . $weekly2['furniture_id'] . "'"
           );

$OwnerCount = mysql_fetch_array($query2);
echo "<tr><td width=\"92%\" >Owner Count: $OwnerCount<form><input type=\"submit\" value=\"Owner Last Online\"></form></td></tr>";

It's because your echo ing an array, try print_r($Ownercount); and you should see the array (and the keys).

Example:

echo $Ownercount[0];

Should return the first key in the array (which is probably what you want).

you can put an alias on the query, like this :

COUNT(DISTINCT id) as total

and then call

$Ownercount["total"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM