Re: How to count same text results from DB?

From: Date: Tue, 03 Oct 2000 14:10:35 +0000
Subject: Re: How to count same text results from DB?
References: 1 2 3 4 5 6  Groups: php.db 
Request: Send a blank email to php-db+get-3265@lists.php.net to get a copy of this message
Clear, thanks for explanation, but I use bloody ODBC to connect bloody M$ Access... there is missing few things such as fething data into aray... Vojta > > > $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. > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.db (#3265) next »