Re: object/array with repeating values (WORKS)

From: Date: Wed, 21 Feb 2001 01:32:11 +0000
Subject: Re: object/array with repeating values (WORKS)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-40870@lists.php.net to get a copy of this message
doff, I knew there had to be a simple answer. Works great, thanks. At 02:26 PM 2/21/01 +1300, Simon Garner wrote: >From: "Jared Howard" <webbie@deanox.com> > >> I'm make an object or an array from the results of a query to my MySQL >> database. The value returned is entered in <option>s and any repeated >> values are unwanted. Is there a way to remove them easily? >> >> eg. >> <select> >> <? $qid = mysql_query("SELECT this FROM that WHERE here"); >> while ($r = mysql_fetch_object($qid)) { ?> >> <option><?=$r->this?></option> >> <? } ?> >> </select> >> >> I was thinking of creating an array before the while, then in the while >add >> each "$r->this" if "(! in_array($arr))". Then I would have to do >> another >> while with the <option> included. But I'm not really sure how to add >> elements to existing arrays. And that might not even be the best way. >Any >> iteas? >> > > >IMHO: always make the database manipulate the data for you, if it can. It's >usually much faster, and requires less code. > >In this case just do: > >SELECT DISTINCT this FROM that WHERE here > >and you won't get any duplicates. Great huh? :) > >Refer to the MySQL manual at http://www.mysql.com/docs/ for more >details. > > >Cheers > >Simon Garner > > >-- >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 >

« previous php.general (#40870) next »