[英]Imploding to mysqli_fetch_array()
Im new to web development. 我是Web开发的新手。 I need the array like following 我需要像下面的数组
["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"] [“水星”,“金星”,“地球”,“火星”,“木星”,“土星”,“天王星”,“海王星”]
I tried. 我试过了。 But I failed.I connected the database. 但是我失败了,我连接了数据库。 How can I make it? 我该怎么做?
my array-code 我的数组代码
$count=0;
$sql="SELECT name FROM planet";
$sql_run=mysqli_query($con,$sql);
while($row = mysqli_fetch_assoc($sql_run))
{
$result[] = "'".implode("\'",$row)."'".",";
echo $result[$count++];
}
By using above code, i couldn't get the result what I expected. 通过使用上述代码,我无法获得预期的结果。
Each fetch returns one planet in associative array. 每次获取将以关联数组返回一个行星。 To get array of rows, you have to do: 要获取行数组,您必须执行以下操作:
$list = array();
while($row = mysqli_fetch_assoc($sql_run)) {
array_push($list, $row['name']);
}
var_dump($list);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.