Page 1 of 1

multidimensional arrays - form menu/list boxes

Posted: Tue Oct 14, 2003 8:11 pm
by gjb79
I have a form that uses list/menu boxes to allow a user to select multiple items from the list. Once selected these items are to be logged into a sql database, each selected item as its own seperate insertion into the table.

I understand that the list boxes submit variables as arrays. How can I setup my insert sql statment to insert the value of each item into the table seperately?

I thought about using a loop to do this, where the insert clause would loop until the list of items in the array ended. The table would have 2 columns aside from the unique id column. one would be a set variable $pageid the other would be the array.

Does anybody know how to handle this situation?

Thanks.

Posted: Tue Oct 14, 2003 10:16 pm
by volka
hm, could you please explain in more detail. I don't get the multidim-array part of your approach.

maybe starting with this simple example

Code: Select all

<html>
	<body>
		<pre>
<?php
if(isset($_POST['choices']) && is_array($_POST['choices']))
{
	foreach($_POST['choices'] as $item)
	{
		$query = 'INSERT ... '.$item;
		echo htmlentities($query), "\n";
	}
}
?>		
		</pre>
		<form method="post">
			<select name="choices[]" multiple="multiple">
				<option value="1">a</option>
				<option value="2">b</option>
				<option value="3">c</option>
				<option value="4">d</option>
			</select>
			<input type="submit" />
		</form>
	</body>
</html>
you can show me what you want to do.