Re: set array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/25/2013 9:53 PM, John Taylor-Johnston wrote:
I have a SET field in MYSQL.
'1. Type One','2. Type Two','3. Type Three'

The user can multi-select
<select name="DPRtype[]" multiple>
<option value="1. Type One">
<option value="2. Type Two">
<option value="3. Type Three">
</select>

I just dont know how to express $_POST[DPRtype] to be able to build the
$SQL to express the separate possibilities.

$sql = "UPDATE `taylorjo`.`CRTP_CGA`
SET
`DPRtype` = '$_POST[DPRtype]'
";


Thanks. Not a newbie. I should know how to do this. I just don't code
every day.

One google search later I found this:

For example, suppose that a column is specified as SET('a','b','c','d'):
mysql> CREATE TABLE myset (col SET('a', 'b', 'c', 'd'));


If you insert the values 'a,d', 'd,a', 'a,d,d', 'a,d,a', and 'd,a,d':
mysql> INSERT INTO myset (col) VALUES
-> ('a,d'), ('d,a'), ('a,d,a'), ('a,d,d'), ('d,a,d');
Query OK, 5 rows affected (0.01 sec)
Records: 5  Duplicates: 0  Warnings: 0


It would appear that you need to built a comma-separated string :
$setvals='';
foreach($_POST['DPRtype'] as $item)
	if ($setvals<>'')
		$setvals .= ",".$item;
	else
		$setvals .= $item;
and then do:

set DPRtype=('$setvals')

in your query.

here's the link to this info:
http://dev.mysql.com/doc/refman/5.0/en/set.html

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux