I am using drop down menu to create a user generate pgsql query. It works perfectly, however, I am now trying to convert it to work with multiple selections. I have run into 2 separate issues. When I add multiple to it is no longer a drop down list, it behaves more like a scrolling wheel. As a note, the options are populated by an initial db query.
<select multiple name="userSite" class="form-dropdown validate[required]">
-While I am able to select multiple options, the query is only returning the first selected, rather than the results for all of the selected options.
ini_set('error_reporting', E_ALL);
ini_set("display_errors", 1);
$site= $_POST["userSite"];
$datea= $_POST["userDatea"];
$table= $_POST["userTable"];
$datez= $_POST["userDatez"];
// You need to do all of this if and only if this is a post request
// Also this method of detecting a post request is more consistent
if( !empty($_SERVER['REQUEST_METHOD']) && (strcasecmp($_SERVER['REQUEST_METHOD'], 'post')===0) ) {
// Create connection
$conn = pg_connect("host=xxxxxxxxxx port=xxxx dbname=db user=xxx password=mypassword");
// Check connection
if (!$conn) {
echo "Did not connect.
";
exit;
}
$result = pg_query($conn,
"SELECT *
FROM
db.$table
WHERE
$table.site_id = '$site' AND
$table.created_on BETWEEN '$datea' AND '$datez' AND
$table.soft_delete_id = '0';");
if (!$result) {
echo "Query failed.
";
exit;
}
$num_fields = pg_num_fields($result);
$headers = array();
for ($i = 0; $i < $num_fields; $i++)
{
$headers[] = pg_field_name($result , $i);
}
$fp = fopen('php://output', 'w');
if ($fp && $result)
{
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="customreport.csv"');
header('Pragma: no-cache');
header('Expires: 0');
fputcsv($fp, $headers);
while ($row = pg_fetch_row($result))
{
fputcsv($fp, array_values($row));
}
die;
}
exit('It works');
}