note 19928 deleted from function.implode by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 13:10:57 +0000 |
| Subject: | note 19928 deleted from function.implode by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189711@lists.php.net to get a copy of this message | ||
Note Submitter: php at woodenpickle dot com
----
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