note 3087 deleted from function.implode by jimw

From: Date: Thu, 20 Dec 2001 22:26:21 +0000
Subject: note 3087 deleted from function.implode by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-23495@lists.php.net to get a copy of this message
A good use for this function is to generate dynamic dropdown SELECT boxes derived from a column in a database.<p> An example of this would be to create a function called GetDistinctArray() which essentially returns an array generated from a query like <br> "SELECT DISTINCT $COLUMN FROM $TABLE". <br> Once you have an array say of distinct categories, implode lets you spit them out into a SELECT statement with:<br> echo '<br> <SELECT NAME="CATEGORY">';<br> $CATEGORY = "Foo";<br> $CatArray = <br> GetDistinctArray("CATEGORY",$DATABASE,$TABLE);<br> $OPTIONS = implode("<OPTION>",$CatArray);<br> echo '<SELECT NAME = "CATEGORY">';<br> print "<OPTION>$OPTIONS<BR></SELECT>";<br> <br> The same could have been done by simply doing a query, looping through the array elements, but this is much cleaner and the function is reusable for any other dropdowns..

« previous php.notes (#23495) next »