Re: array count()
| From: | Brad Sacks | Date: | Tue, 11 Jul 2000 05:23:50 +0000 |
| Subject: | Re: array count() | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-5855@lists.php.net to get a copy of this message | ||
I thank you for your answer. What I really want to do is count how many
records are in the db table that are in a catagory. I have 7 catagories and
want to return a count of each without making 7 queries.
David Robley wrote:
> On 10 Jul, Brad Sacks wrote:
> > I have an record set from a MySql database;
> > $record = mysql_fetch_array($result);
> > I want to be able to count the number of elements inside that have the
> > same key. Like $record["blah"];
> > I want to know how many record blahs there are in the record set. I hope
> > someone out there can help. I used $num = count($record["advoc"]); but I
> > new it was wrong and it returned 1. when there are 12 records. I've been
> > pouring over the manual for an hour.
> >
>
> I'm not quite sure that I understand what it is you are asking, but I'll
> answer anyway :-)
>
> First up, $record only contains one row from your table. Perhaps you
> want to use mysql_num_rows to find out how many rows were returned?
> Alternatively, if you want to find out how many rows in a table match an
> expression or value in a particular field or fields, you can use the
> MySQL COUNT() function.
>
> eg SELECT COUNT(*) AS howmany FROM contacts WHERE name LIKE '%SMITH%'
>
> will return one row containing one field howmany, showing how many names
> like SMITH are in your contacts table.
>
> Cheers
> --
> David Robley | WEBMASTER & Mail List Admin
> RESEARCH CENTRE FOR INJURY STUDIES |
> http://www.nisu.flinders.edu.au/
> AusEinet |
> http://auseinet.flinders.edu.au/
> Flinders University, ADELAIDE, SOUTH AUSTRALIA
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net