为二维数组赋值
我试图将数据库中的值分配给二维数组,但它只显示最后一项。
这是代码:
while($row = mysql_fetch_array($results)){
$MyData = array( array("Focus Area", $row["FocusArea"]),
array("Finding Title", $row["FindingTitle"]),
array("Finding Detail", $row["FindindDetail"])
);
}//End While
我做错了什么请帮忙。
I am trying to assign values from a db to a 2d array, but its only showing the last iterms.
Here is the code:
while($row = mysql_fetch_array($results)){
$MyData = array( array("Focus Area", $row["FocusArea"]),
array("Finding Title", $row["FindingTitle"]),
array("Finding Detail", $row["FindindDetail"])
);
}//End While
What am I doing wrong please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我还建议创建一个函数就足够了
,因为从数据库获取数组是一个非常常见的例程。
因此,您将能够在一行中获取数据,
would be enough
I'd also suggest to make a function, as getting an array from db is a very common routine.
So, you'll be able to get your data in one line,
这就能解决问题
this will do the trick
每次循环运行时都会声明一个新数组。将其声明为 while 循环之外,并添加新值。
You're declaring a new array each time the loop runs. Declare it out of the while loop, and add the new values.