php smarty 嵌套循环问题
$phpfile='user.php';//页面文件名$page=isset($_GET['page'])?$_GET['page']:1;//默认页码$counts=m...
$phpfile = 'user.php';//页面文件名
$page= isset($_GET['page'])?$_GET['page']:1;//默认页码
$counts = mysql_num_rows(mysql_query("SELECT * FROM blog where id = '$_SESSION[id]'"));//获取需要的数据总条数
$sql2="SELECT * FROM blog where id = '$_SESSION[id]' order by blogid desc";//定义查询语句SQL
$getpageinfo = page($page,$counts,$phpfile);//调用函数,生成分页HTML 和 SQL LIMIT 子句
$sql2.=$getpageinfo['sqllimit'];//组合完整的SQL语句
$data = $row1 = array();//初始化数组
$result = mysql_query($sql2);//获取结果集
//将数据装入$data数组
while($row1 = mysql_fetch_array($result)){
$data[] = array(
"message"=>$row1[message],
"u_update"=>$row1[u_update],
"uptime"=>$row1[uptime],
"u_from"=>$row1[u_from],
"blogid"=>$row1[blogid],
"js"=>"<script lanaguge='javascript'>function pinglun$row1[blogid](){if(document.getElementById('pinglun$row1[blogid]').style.display=='none'){document.getElementById('pinglun$row1[blogid]').style.display='';}else{document.getElementById('pinglun$row1[blogid]').style.display='none';}}</script>",
);
$phpfile1 = 'user.php';//页面文件名
$page1= isset($_GET['page'])?$_GET['page']:1;//默认页码
$counts1 = mysql_num_rows(mysql_query("SELECT * FROM comments where blogid = '$row1[blogid]'"));//获取需要的数据总条数
$sql3="SELECT * FROM comments where blogid = '$row1[blogid]' order by blogid desc";//定义查询语句SQL
$getpageinfo1 = page1($page1,$counts1,$phpfile1);//调用函数,生成分页HTML 和 SQL LIMIT 子句
$sql3.=$getpageinfo1['sqllimit1'];//组合完整的SQL语句
$data1 = $row2 = array();//初始化数组
$result1 = mysql_query($sql3);//获取结果集
//将数据装入$data数组
while($row2 = mysql_fetch_array($result1)){
$data1[] = array(
"message"=>$row2[message],
"u_update"=>$row2[u_update],
"uptime"=>$row2[uptime],
"realname"=>$row2[realname]
);
}
//unset($data1);
print_r($data1);
}
print_r($data);
print_r($data1);
$smarty->assign("data",$data);
上面的print_r($data1);和print_r($data);都可以打印出数组内容,但为什么最后一个print_r($data1);
无法打印出数组内容?内容显示为Array ( )
请问应该怎样解决? 展开
$page= isset($_GET['page'])?$_GET['page']:1;//默认页码
$counts = mysql_num_rows(mysql_query("SELECT * FROM blog where id = '$_SESSION[id]'"));//获取需要的数据总条数
$sql2="SELECT * FROM blog where id = '$_SESSION[id]' order by blogid desc";//定义查询语句SQL
$getpageinfo = page($page,$counts,$phpfile);//调用函数,生成分页HTML 和 SQL LIMIT 子句
$sql2.=$getpageinfo['sqllimit'];//组合完整的SQL语句
$data = $row1 = array();//初始化数组
$result = mysql_query($sql2);//获取结果集
//将数据装入$data数组
while($row1 = mysql_fetch_array($result)){
$data[] = array(
"message"=>$row1[message],
"u_update"=>$row1[u_update],
"uptime"=>$row1[uptime],
"u_from"=>$row1[u_from],
"blogid"=>$row1[blogid],
"js"=>"<script lanaguge='javascript'>function pinglun$row1[blogid](){if(document.getElementById('pinglun$row1[blogid]').style.display=='none'){document.getElementById('pinglun$row1[blogid]').style.display='';}else{document.getElementById('pinglun$row1[blogid]').style.display='none';}}</script>",
);
$phpfile1 = 'user.php';//页面文件名
$page1= isset($_GET['page'])?$_GET['page']:1;//默认页码
$counts1 = mysql_num_rows(mysql_query("SELECT * FROM comments where blogid = '$row1[blogid]'"));//获取需要的数据总条数
$sql3="SELECT * FROM comments where blogid = '$row1[blogid]' order by blogid desc";//定义查询语句SQL
$getpageinfo1 = page1($page1,$counts1,$phpfile1);//调用函数,生成分页HTML 和 SQL LIMIT 子句
$sql3.=$getpageinfo1['sqllimit1'];//组合完整的SQL语句
$data1 = $row2 = array();//初始化数组
$result1 = mysql_query($sql3);//获取结果集
//将数据装入$data数组
while($row2 = mysql_fetch_array($result1)){
$data1[] = array(
"message"=>$row2[message],
"u_update"=>$row2[u_update],
"uptime"=>$row2[uptime],
"realname"=>$row2[realname]
);
}
//unset($data1);
print_r($data1);
}
print_r($data);
print_r($data1);
$smarty->assign("data",$data);
上面的print_r($data1);和print_r($data);都可以打印出数组内容,但为什么最后一个print_r($data1);
无法打印出数组内容?内容显示为Array ( )
请问应该怎样解决? 展开
2个回答
展开全部
是你数据组和写法不对.
把子分类组织成数组,作为主分类的一个元素.结构类似这样的.
array(array('title'=>'大分类一','Sloop'=>array('title'=>'子分类一')))
我习惯用section,所以用section给你举例子.
<dl>
<dt><a href="#"><></a></dt>//大分类的标题
//处理大分类下的小分类,sloop是一个数组.
<dd><a href="#"><></a></dd>
<dl>
把子分类组织成数组,作为主分类的一个元素.结构类似这样的.
array(array('title'=>'大分类一','Sloop'=>array('title'=>'子分类一')))
我习惯用section,所以用section给你举例子.
<dl>
<dt><a href="#"><></a></dt>//大分类的标题
//处理大分类下的小分类,sloop是一个数组.
<dd><a href="#"><></a></dd>
<dl>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询