From: "Jared Howard" <[EMAIL PROTECTED]>

> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to