Re: unique array items

From: Date: Thu, 26 Oct 2000 02:18:00 +0000
Subject: Re: unique array items
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-22016@lists.php.net to get a copy of this message
On Thu, 26 Oct 2000, Kevin Waterson wrote: > David Robley wrote: > > > > mysql_pconnect("localhost","$UserName","$Password") OR > > > DIE > > > (mysql_error()); > > > $result=mysql("pos","SELECT DISTINCT PayTo FROM ChequeBook"); > > > while ($row = mysql_fetch_array($result)) { > > > echo "<option > > > value=\"$row[PayTo]\">$row[PayTo]</option>"; > > > } > > > > Kevin > > I'm not sure what you mean here by 'will not accept them as variables'. > > > > If you are trying to build a drodown list, you of course need the > > appropriate SELECT tag info around the option and it all needs to be in a > > form to display correctly. > yes, this is a code exept and the full code has a form and the required > <select></select>. all works well _exept_ if I use DISTINCT. So what I > am looking for is a method to use array_unique() with > mysql_fetch_array() > to supply the unique items in the array. > -- > Kind regards > > Kevin Waterson You can't do that in the way you suggest; mysql_fetch_array only returns an array of the current row which of course only has one PayTo in it. you'd need to loop throguh all the records, add the PayTo values to an arrary and then do array_unique things to it. IMHO it would be better to work out how to use DISTINCT to do it, and certainly less cpu-intensive. So if you can explain what's not happening or what's happening that shouldn't..... -- 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 (#22016) next »