I am trying to write a script that will allow a user to select one or more items from a list to create a CSV file. I am having trouble integrating the Array feature of the multiple select list with MySQL.
Pertinent code:
<?php
// Processes the form below
if ($submit) {
// The line below is where I have problems. I don't know how to reference the Field1 Array created with the select box in the form.
$result2 = mysql_query("select * from TableName where Field1=$Field1",$db);
while ($row = mysql_fetch_array($result2)) {
// Eventually it will create a CSV, but for testing purposes I am just printing to screen.
printf ("%s,%s,%s\r\n", $row["Field1"], $row["Field2"], $row["Field3"]);
}
}
// Initially Displays all items in the database (user can select one or multiple items to be processed)
$result = mysql_query("select * from TableName");
print <<<END
<form name="FormName" action="$PHP_SELF" method="post">
<select name="Field1[]" multiple size="10">
END;
while ($row = mysql_fetch_array($result)) {
printf ("<option value=\"%s\">%s</option>\n", $row["Field1"], $row["Field1"]);
}
print <<<END
</select><br>
<input type="submit" name="submit" value="Submit">
</form>
END;
?>
Any help would be greatly appreciated. Thanks in advance!