Hello every body is it possible to pass an array containing some data to a function and put this array of data in a WHERE condition of a mysql query? Please, take a look to my code if it's correct. Anyway it is not working at the moment, it prints "No results" ...
public function target_query($ids_array){
include_once 'connection.php';
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$ids = join("','",$ids_array);
$sql = "SELECT codice_target FROM customer WHERE id_customer IN ('$ids')";
$result = $conn->query($sql);
$arraytoclass = array();
if ($result->num_rows > 0) {
// output data of each row
//echo "tutto ok";
while($row = $result->fetch_row()) {
//echo "Codice target: " . $row["codice_target"]."<br>";
$arraytoclass[] = $row;
//echo "codice target:".$arraytoclass[$i]['codice_target'];
}
//print_r($arraytoclass);
return $arraytoclass;
//print_r($arraytoclass);
} else {
echo "NO results";
}
return $arraytoclass;
$conn->close();
}
The result of the query will be passed inside another function here below:
public function fputToFile($file, $allexportfields, $object, $ae)
{
if($allexportfields && $file && $object && $ae)
{
//one ready for export product
$readyForExport = array();
//put in correct sort order
foreach ($allexportfields as $value)
{
$object = $this->processDecimalSettings($object, $ae, $value);
$readyForExport[$value] = iconv("UTF-8", $ae->charset, $object[$value]);
}
$arraytoclass = $this->target_query($readyForExport['id_customer']);
print_r ($arraytoclass);
// and so on...
// and so on...
Many thanks in advance.