0

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>";
2
  • EDIT: I added these lines and I get the result: 6,6 $string=implode(",",$OwnerCount); echo $string; Commented Feb 23, 2013 at 5:30
  • Nevermind, I solved it, I added [0] and got the result 6 as I wanted, so my code is $string=implode(",",$OwnerCount); echo $string[0]; Commented Feb 23, 2013 at 5:35

2 Answers 2

3

It's because your echoing 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).

Sign up to request clarification or add additional context in comments.

1 Comment

Echo $OwnerCount[0]; and I get nothing(Owner Count: ) Print_r($OwnerCount); and I get the result Owner Count: print_r()
0

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

COUNT(DISTINCT id) as total

and then call

$Ownercount["total"];

1 Comment

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.