我正在尝试从 MySQL 数据库中获取一维数组中的列表或电子邮件。 但是,我得到的是多维数组,而不是数组:
$query = "SELECT DISTINCT `EmailAddress` FROM `Emails` WHERE `JobID` = 1";
$result = $conn->query($query);
if (!$result) {
printf("Query failed: %s\n", $mysqli->error);
exit;
}
while ($row = $result->fetch_row()) {
$rows[] = $row;
}
$result->close();
$conn->close();
var_dump($rows); // This will return array(2) { [0]=> array(1) { [0]=> string(24) "abc@abc.com" } [1]=> array(1) { [0]=> string(17) "hello@gmail.com" } }
//This is how array should be
$MyV = array("abc@abc.com", "hello@gmail.com");
var_dump($MyV); //this is an array I need to have: array(2) { [0]=> string(11) "Abc@abc.com" [1]=> string(11) "hello@g.com" }
最佳答案
while($row = $result->fetch_assoc()) {
$rows[]=$row['EmailAddress'];
}
关于php - 如何使用 MySQLi 获取单列值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30761740/