从MySQL获得表到PHP数组行 [英] Get rows from mysql table to php arrays

查看:114
本文介绍了从MySQL获得表到PHP数组行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能得到一个MySQL表的每一行,并把它放在一个PHP数组?我需要为这个多维数组?所有这一切的目的是一个谷歌地图上显示稍后的几个问题。

How can i get every row of a mysql table and put it in a php array? Do i need a multidimensional array for this? The purpose of all this is to display some points on a google map later on.

推荐答案

您需要得到所有你从表中想要的数据。像这样将工作:

You need to get all the data that you want from the table. Something like this would work:

$SQLCommand = "SELECT someFieldName FROM yourTableName";

这行进入你的表,并从表中获取someFieldName的数据。如果你想获得多个列,你可以添加更多的字段名,其中someFieldName。

This line goes into your table and gets the data in 'someFieldName' from your table. You can add more field names where 'someFieldName' if you want to get more than one column.

$result = mysql_query($SQLCommand); // This line executes the MySQL query that you typed above

$yourArray = array(); // make a new array to hold all your data


$index = 0;
while($row = mysql_fetch_assoc($result)){ // loop to store the data in an associative array.
     $yourArray[$index] = $row;
     $index++;
}

以上循环经过的每一行,并将其存储你所取得的新的数组中的元素。然后,你可以做任何你想要与信息,如打印出来的画面:

The above loop goes through each row and stores it as an element in the new array you had made. Then you can do whatever you want with that info, like print it out to the screen:

echo $row[theRowYouWant][someFieldName];

因此​​,如果$ theRowYouWant等于4,这将是从第5行(记住,行0开始!)。中的数据(在这种情况下,'someFieldName')

So if $theRowYouWant is equal to 4, it would be the data(in this case, 'someFieldName') from the 5th row(remember, rows start at 0!).

这篇关于从MySQL获得表到PHP数组行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆