嗨我有这个代码,它(records2)由于某种原因返回多维数组。 有人可以帮助我并指出原因吗?我需要一个简单的单维数组。
function getBook() {
global $dbc;
global $id;
//connect to database
require('db.php');
//make the query
$query = "SELECT title, fiction, publisher, summary, pages FROM bookShelf WHERE id=$id;";
$runQuery = @mysqli_query($dbc, $query); //run the query
$records2 = array();
while ($row = mysqli_fetch_assoc($runQuery)) {
$records2[] = $row;
}
echo '<pre>';
print_r($records2);
echo '</pre>';
}
答案 0 :(得分:-1)
$records2 = array();
$records2 = mysqli_fetch_assoc($runQuery);
这里mysqli_fetch_assoc()函数将结果行作为单维关联数组提取,没有任何循环。