Re: How to count same text results from DB?

From: Date: Tue, 03 Oct 2000 13:15:59 +0000
Subject: Re: How to count same text results from DB?
References: 1 2 3 4 5  Groups: php.db 
Request: Send a blank email to php-db+get-3261@lists.php.net to get a copy of this message
> > $alldata=array(); > > $alldata=suck_all_data_into_an_array(); > > Ok, so something like: $alldata=array(John, Mark, Paul, Steve, Joseph); ? When you do a query on the database, the information is presented back to you in the form of an array. Under Oracle it returns an associated array containing/like: $data[<fieldname>][<record/row number>] I'm not sure how MS SQL dose it but it will be similar. > > for ($i=0 ; $i<count($alldata) ; $i++) > > { > > $mycount[ $alldata["NAME"][$i] ] ++; > > Sorry, what this line exacly do? I have fight with arrays all the time... do > you know place where I can see some good tutorial for arrays? > How the contens of this array looks like? It should be: $mycount[ $alldata[<fieldname>][$i] ] ++; This produces an associated array where the ``select''ed name is the index. The array is populated like a historgram, to produce results like $mycount["John"] = 5; $mycount["Mark"] = 3; $mycount["Paul"] = 2; etc... > > do_your_stuff(); > > } > > > > reset($mycount) > > while (list($k,$v) = each($mycount)) > > { > > echo "There are $v students with the name $k<br>"; > > } Inorder to put out the information you will have to use list() and each(). I hope this is a bit clearer? David.

« previous php.db (#3261) next »