我需要以关联数组的形式获取表中每个单元格的值
$sqlStatemnt = "SELECT artist, track_name
FROM Tracks where artist like 'bong' and track_name like 'bong' LIMIT 5";
这就是我的php如何处理它
$rs = $mySQL->query($sqlStatemnt);
print_r($rs);
打印给我看这个
mysqli_result Object ( [current_field] => 0 [field_count] => 2 [lengths] => [num_rows] => 0 [type] => 0 )
如何访问表"track_name"one_answers"artist"?
$result = $mysqli->query($query);
/* numeric array */
$row = $result->fetch_array(MYSQLI_NUM); //To get Indexed array
$row = $result->fetch_array(MYSQLI_ASSOC);//To get associative array
感谢
有一个与mysqli结果对象相关的fetch_assoc
。你可以试试这种
artist = array();
track_name = array();
while(($row = $result->fetch_assoc()) !== FALSE) {
$artist[] = $row['artist'];
$track_name[] = $row['track_name'];
}
我希望这与您的实施相匹配。
在此处查找有关fetch_assoc的更多信息http://php.net/manual/en/mysqli-result.fetch-assoc.php