[英]Storing multiple column values into PHP array from MySQL query
I currently have an array that stores the values of one column from the database and that works fine however I want to store more than one column value. 我目前有一个数组,用于存储数据库中一列的值,并且工作正常,但是我想存储多个列值。 So in my example I want a team and their venue stored in the same array index. 因此,在我的示例中,我希望一个团队及其场地存储在相同的数组索引中。 I can't seem find a way to do this. 我似乎找不到解决办法。
If anyone can perhaps help that would be much appreciated. 如果有人可以提供帮助,将不胜感激。
Do you mean something like this? 你的意思是这样吗?
$i = 0;
$my_array = array();
while ($row = mysql_fetch_assoc($result))
{
$my_array[$i]['name'] = $row['names'];
$my_array[$i]['otherfield'] = $row['otherfield'];
$i++;
}
now you can do something like this 现在你可以做这样的事情
echo $my_array[2]['name'];
Simply do : 只需做:
$rows = [];
while($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.