Re: array count()

From: Date: Tue, 11 Jul 2000 05:18:40 +0000
Subject: Re: array count()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-5854@lists.php.net to get a copy of this message
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

« previous php.general (#5854) next »