...

View Full Version : select box to array



esthera
03-19-2007, 09:51 AM
I have a multiple select box named

<select name=schools[] multiple>

now my php to retrieve thse is

$school=$_REQUEST['school'];
foreach ($school as $k=>$v)
{
$sql=$sql."reason like '".$v."%'";
if ($n>0){
$sql=$sql." or ";
}

now instead of adding each school to the sql it's just writing it out as
array instead of the school name from the select -- what am i doing wrong?

devinemke
03-19-2007, 10:21 PM
<?php
if (!isset($_POST['submit']))
{
echo '
<form action="" method="POST">
<select name="num[]" size="5" multiple>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select><br>
<input type="submit" name="submit" value="submit">
</form>
';
}
else
{
if (isset($_POST['num']))
{
foreach ($_POST['num'] as $value) {$sql_array[] = "'" . $value . "'";}
$sql = 'SELECT * FROM table WHERE num IN(' . implode(',', $sql_array) . ')';
echo $sql;
}
else
{
echo 'you did not select any numbers';
}
}
?>

esthera
03-20-2007, 07:58 AM
will this work with request also?
as that is what i did but it doesn't seem to work



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum