It's actually a very simple solution, and you should do it all in a
single INSERT. Putting INSERTs in a loop will kill your performance
when you try to scale.
$sql4 = 'INSERT INTO temp (example) VALUES (' . implode('),(',
$_POST["categoriesIN"]) . ')';
$result4 = mysql_query($sql4, $db);
That example does not sanitize the data before inserting.
Brent
On Mon, Feb 23, 2009 at 10:25 AM, PJ <[email protected]> wrote:
> I think this is a tough one... and way above my head:
> PLEASE READ ALL OF THE ABOVE TO UNDERSTAND WHAT I AM TRYING TO DO.
> Having a bit of a rough time figuring out how to formulate php-mysql to
> insert data into fields using a multiple dropdown box in a form.
>
> to post I am using the following:
> snip...
> $categoriesIN = $_POST["categoriesIN"];
>
> ...snip...
>
> <select name="$categoriesIN[]" multiple="multiple">
> <OPTION>Choose Categories...</option>
> <OPTION VALUE="<? echo $categoriesIN; ?>">1
> <OPTION VALUE="<? echo $categoriesIN; ?>">2
> <OPTION VALUE="<? echo $categoriesIN; ?>">3
> <OPTION VALUE="<? echo $categoriesIN; ?>">4
> <OPTION VALUE="<? echo $categoriesIN; ?>">5
> </SELECT>
>
> ...snip...
>
> $sql4 = "FOR ( $ii = 0 ; $ii < count($categoriesIN) ; $ii++ )
> INSERT INTO temp (example) $categoriesIN[$ii]" ;
> $result4 = mysql_query($sql4, $db);
> ...snip
>
> this does not work! The other posts work like a charm... but this...
>
> I cannot figure out what I should be entering where... I have tried several
> different configurations, but nothing seems to work...
>
> I found this as a model for entering the selections but can't figure out how
> to modify it for my needs:
>
> <select name="branch_no[]" multiple="multiple" size="5">
> <option > Choose your location(s) </option>
> <option value="3100">3100</option>
> <option value="3105">3105</option>
> <option value="3503"> 3503</option>
> <option value="3504"> 3504</option>
> </select>
>
> What I would like to do is something like the following:
> <select name="$categoriesIN[]" multiple="multiple">
> <OPTION>Choose Categories...</option>
> <OPTION VALUE="1">History
> <OPTION VALUE="2">Temples
> <OPTION VALUE="2">Pharaohs and Queens
> <OPTION VALUE="4">Cleopatra
> <OPTION VALUE="4">Mummies
> </SELECT>
> and going further, I would like to be able to use a table that actually holds
> these values to feed them to the code above. I am sure this is possible but
> it must take some huge knowledge and experience to do it.
>
> BUT ...
> as I look at things, I am wondering if the FOR statement in the above should
> be used to do several INSERTs, that is, one $sql(number) per selected
> category... now, would that require many $sqls or many INSERTs within the
> $sql ?
>
>
> --
>
> Phil Jourdan --- [email protected]
> http://www.ptahhotep.com
> http://www.chiccantine.com
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/[email protected]
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php