【发布时间】:2013-01-20 05:03:43
【问题描述】:
这里的基本 php 问题。以下 SQL 代码返回一个数组,其中包含一个名为“日期”的键。我要做的就是根据键名解析“日期”值。有什么帮助吗?
$result = mysql_query("SELECT * FROM `table` WHERE columnName ='value'") or die(mysql_error());
$data = array();
while ( $row = mysql_fetch_assoc($result) )
{
$data[] = $row;
}
echo $data->{'date'}
【问题讨论】:
-
不,你所做的是调用对象属性,我的意思是
$data->{'date'} -
Please, don't use
mysql_*functions in new code。它们不再维护and are officially deprecated。看到red box?改为了解prepared statements,并使用PDO 或MySQLi - this article 将帮助您决定哪个。如果你选择 PDO,here is a good tutorial. -
只是一个建议,您可以使用 NOTORM 来处理 sql 查询,这是一个很棒的库 notorm.com
标签: php sql arrays json parsing