- Edited
I have a script where you select the users you want and then we export that information to CSV, I dont know how many names the post array will receive so I am adding them all together into a new array and then doing a select where in (that array) to find them and add them to the csv output.
The following works fine when you have just one person to export, but the minute you add more the csv only has the headers in. I have run checks on the select statement and I believe this is where it is going wrong as when I have two or more names the row count is 0. I have printed the new ($match_array1) and it has the values in there so maybe its the sql statement that is not correct, it is not throwing any errors or warnings:
if(isset($_POST['header'])){
$user_in_post = $_POST['user_result'];
$match_array1 = array();
foreach($user_in_post as $user_to_check)
{
$match_array1[] = $name_to_check;
}
$hdr_user_to_export = implode(",",$match_array1);
$sql = "SELECT first_name, last_name FROM names WHERE first_name IN ('".$hdr_user_to_export."')";
$results = $DB_con3->query($sql);
$output = "";
`
//Set header values
$headers = array("First Name", "Last Name");
`
//Insert header values to $output
foreach($headers as $h){
$output .= $h . ",";
}
$output = rtrim($output, ","). "\n";
//Iterate through results
while($row = $results->fetch(PDO::FETCH_ASSOC)) {
foreach($row as $cell){
//Comma-separate each value
$output .= $cell.",";
}
//Remove last comma of each line and add newline
$output = rtrim($output, ",") . "\n";
}
//Set headers
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="ORA_ASE_FUNCTIONAL_SECURITY_CUSTOM_ROLES.csv"');
//Output
echo $output;
exit;
} `
Thanks!