Hello每个主体是否可以将包含一些数据的数组传递给函数并将此数组数据放在mysql查询的WHERE条件中? 如果它是正确的,请查看我的代码。无论如何它现在不工作,它打印"没有结果" ......
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();
}
查询结果将在下面的另一个函数中传递:
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...
非常感谢提前。