Re: array_unique not always unique
| From: | jeremy brand | Date: | Fri, 15 Dec 2000 21:55:42 +0000 |
| Subject: | Re: array_unique not always unique | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-30592@lists.php.net to get a copy of this message | ||
You may want to check out libHtmlForm. You can easily do a pull down
by simply passing it an array. The array keys are the value=""'s for
the <option> tags and the array values the descriptions for each
option tag.
libHtmlForm can be found here:
http://www.nirvani.net/software/libHtmlForm-1.0.0.php.asc
Jeremy Brand :: Sr. Software Engineer :: 408-245-9058 :: jeremy@nirvani.net
http://www.JeremyBrand.com/Jeremy/Brand/Jeremy_Brand.html
for more
Get your own Free, Private email at http://www.smackdown.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
At least for the people who send me mail about a new language that
they're designing, the general advice is: do it to learn about
how to write a compiler. --Dennis Ritchie
On Fri, 15 Dec 2000 kris@grinz.com wrote:
> Date: Fri, 15 Dec 2000 15:42:22 -0600
> From: kris@grinz.com
> To: php-general@lists.php.net
> Subject: [PHP] array_unique not always unique
>
> Hi, I have a function I wrote recently which builds a pulldown menu.
> Sometimes it builds a pulldown showing only unique values (which
> is what I want), and sometimes it builds a pulldown with duplicate
> values listed. Here is a sample data list (hand written based on sql
> data) and which pulldowns are rendered properly. Also attached is
> the script. Can someone tell me how to make this work all the
> time? Currently, it only works about half the time. Its probably
> something simple but not much docs on this that I could find. I
> found one thing about this at
> http://www.php.net/manual/function.array-unique.php by
> jllamas@bal.com.mx but I dont understand it enough to use the
> info to solve my problem. Thanks, Kris (everything u need is
> below)
>
> data map (comma seperated "simulated sql output"):
>
> type=price data =$100.00, $200.00, $100.00, $100.00
> this renders properly with my function, showing unique values only.
>
> type=size data=19,19,19,19
> this renders improperly, showing 19 twice in the pulldown.
>
> type=bottommat data=blue,orange,red,blue
> this renders properly, showing unique values only.
>
> type=topmat data=green,green,red,red
> this renders improperly, showing each unique twice.
>
> type=frametype data=cherry,cherry,black,black
> this renders improperly, showing each unique twice.
>
> // BEGIN CODE
> $psqlhost="what.ever.com"; $psqldb="whatever";
> function GetPullDown($type){
> global $id, $name, $descript, $price, $size, $image,
> $bottommat, $topmat, $frametype, $startid, $psqldb, $psqlhost,
> $progname, $itemcheck;
> $call="select $type from products";
> $db_connect=pg_connect("host=$psqlhost dbname=$psqldb");
> $result=pg_exec($db_connect, "$call");
> $rows=pg_numrows($result);
> echo"<select name=\"$type\" size=1>";
> $x=0;
> $sortmp=array();
> while($x<$rows){
> $arra=pg_fetch_array($result, $x);
> $sortmp[$x]=$arra[0];
> $x++;
> }
> $final=array_unique($sortmp);
> $finalcount=count($final);
> $y=0;
> while($y<$finalcount){
> if($final[$y]==""){ echo" "; }
> else{
> if($final[$y]==${$type}){
> echo"<option selected>$final[$y]\n";
> }
> else{ echo"<option>$final[$y]\n"; }
> }
> $y++;
> }
> echo"<option>Other\n";
> echo"</select>";
> }
> echo"<table><tr><td
> align=\"right\">Price:</td><td>";
> GetPullDown(price);
> /* pricetag used if Other is selected on pulldown */
> echo"<input type=\"text\" name=\"pricetag\"
> size=\"8\">
> </td></tr></table>";
> // END CODE
>
> --
> 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
>
>