views:

53

answers:

1

I want to count some rows in my database and I'm using the following code:

                $tagname = Person;
                $query = "SELECT COUNT(thread_tag_map.tag_id) AS tagcount
                        FROM tags, thread_tag_map
                        WHERE thread_tag_map.tag_id = tags.id
                        AND tags.name = '$tagname'";

                $result = $this->do_query($query);


                return $result;

When I use print_r($result) it shows an associative array Array ( [tagcount] => 3 ).

Shouldn't it be a mysqli object that I have to extract using mysqli_fetch_assoc?

Could someone explain?

A: 

Count returns just a number, but you are executing a sql select statement and this will return something like a rowset, i.e. a bunch of rows (in your case 1) with an element for each column (in you case 1).

The exact details depend on the programming language an api you are using.

Jens Schauder
how should i write the code to just return a nr? i want to return a count on duplicate rows of thread_tag_map.tag_id
never_had_a_name
In principle: take the first element of the result set, extract the single value, from the associative array. I have no idea about the exact syntax since I don't even know the language you are using. This would be a good new question
Jens Schauder