PHP查询mysql数据库返回的数组结果无法分开显示
functionluntan2($id){$sql=mysql_connect("127.0.0.1","root","root");mysql_select_db("L...
function luntan2($id)
{
$sql = mysql_connect("127.0.0.1","root","root");
mysql_select_db("LY",$sql);
$chaxun="SELECT `id` , `ZTai` , `Lei` , `Zhu` , `ZuoZhe` , `Time` FROM `luntan` ORDER BY `luntan`.`Lei` ASC , `luntan`.`HTime` DESC ";
$result = mysql_query($chaxun,$sql);
$arr = array();
while ($row = mysql_fetch_assoc($result))
{
$arr[] = $row;
}
return $arr;
}
上面是查询
返回的数据在另外的网页用print_r(luntan2(1));可以查看到结果:
Array ( [0] => Array ( [id] => 2 [ZTai] => 1 [Lei] => 1 [Zhu] => 论坛版规!!! [ZuoZhe] => 1 [Time] => 2015-1-22 ) [1] => Array ( [id] => 4 [ZTai] => 1 [Lei] => 1 [Zhu] => 实验啦!!! [ZuoZhe] => 1 [Time] => 2015-1-22 ) [2] => Array ( [id] => 3 [ZTai] => 3 [Lei] => 2 [Zhu] => 论坛的第二个帖子! [ZuoZhe] => 5 [Time] => 2015-1-22 ) [3] => Array ( [id] => 1 [ZTai] => 3 [Lei] => 2 [Zhu] => 论坛的第一条帖子!!! [ZuoZhe] => 1 [Time] => 2015-1-22 ) )
但是却分不开这个数组了
当时是想用echo luntan2(1)[0][Time];之类的方法不行
报错:
Parse error: syntax error, unexpected '[' in D:\AppServ\www\LY\LunTan.php on line 145 展开
{
$sql = mysql_connect("127.0.0.1","root","root");
mysql_select_db("LY",$sql);
$chaxun="SELECT `id` , `ZTai` , `Lei` , `Zhu` , `ZuoZhe` , `Time` FROM `luntan` ORDER BY `luntan`.`Lei` ASC , `luntan`.`HTime` DESC ";
$result = mysql_query($chaxun,$sql);
$arr = array();
while ($row = mysql_fetch_assoc($result))
{
$arr[] = $row;
}
return $arr;
}
上面是查询
返回的数据在另外的网页用print_r(luntan2(1));可以查看到结果:
Array ( [0] => Array ( [id] => 2 [ZTai] => 1 [Lei] => 1 [Zhu] => 论坛版规!!! [ZuoZhe] => 1 [Time] => 2015-1-22 ) [1] => Array ( [id] => 4 [ZTai] => 1 [Lei] => 1 [Zhu] => 实验啦!!! [ZuoZhe] => 1 [Time] => 2015-1-22 ) [2] => Array ( [id] => 3 [ZTai] => 3 [Lei] => 2 [Zhu] => 论坛的第二个帖子! [ZuoZhe] => 5 [Time] => 2015-1-22 ) [3] => Array ( [id] => 1 [ZTai] => 3 [Lei] => 2 [Zhu] => 论坛的第一条帖子!!! [ZuoZhe] => 1 [Time] => 2015-1-22 ) )
但是却分不开这个数组了
当时是想用echo luntan2(1)[0][Time];之类的方法不行
报错:
Parse error: syntax error, unexpected '[' in D:\AppServ\www\LY\LunTan.php on line 145 展开
1个回答
推荐于2016-01-10
展开全部
echo luntan2(1)[0][Time];
这种写法只有在php5.4之后才能用,低于5.4可能会报错
这种写法只有在php5.4之后才能用,低于5.4可能会报错
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询