note 19928 added to function.implode
| From: | php at woodenpickle dot com | Date: | Fri, 15 Mar 2002 03:55:17 +0000 |
| Subject: | note 19928 added to function.implode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27828@lists.php.net to get a copy of this message | ||
Hey, I found a good use for implode() today. It came from a need to have a <select name=state
multiple> box on the page that a person could select multiple states from and send those to a
>SELECT * FROM customers WHERE state='$state'; query. But they need to be able to send
just one state also. Well, I changes the html select box to say <select name=state[]
multiple>. This turns $state into an array as you may know. I then, later on in the script, did
this:
$count = count( $state );
if( $count > 1 ) {
$states = implode( "'.'", $state );
$result = $database->query( "SELECT * FROM currentOrders WHERE date>=$from AND date
<=$to AND state IN ('$states')" );
}
//This takes care of multiple states, but if the user sent only one state, I catch it here:
foreach( $state as $value );
if( $value )
$result = $database->query( "SELECT * FROM currentOrders WHERE date>=$from AND
date<=$to AND state='$value'" );
else //This one will catch the ALL states option if they choose that.
$result = $database->query( "SELECT * FROM currentOrders WHERE date>=$from AND
date<=$to" );
Anyway, I thought I'd post this up here in case it might help someone. Or maybe someone could
figure out a better way and enlighten us all.. Have fun.. Bob
--
http://www.php.net/manual/en/function.implode.php
http://master.php.net/manage/user-notes.php?action=edit+19928
http://master.php.net/manage/user-notes.php?action=delete+19928
http://master.php.net/manage/user-notes.php?action=reject+19928