免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2410 | 回复: 2
打印 上一主题 下一主题

[求助]PHPLIB Template的 块循环问题。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-07-31 11:01 |只看该作者 |倒序浏览
谢谢各位!

我想让程序显示出我在MYSQL里取得的数据。

index.php块循环片段
[php]
//***************************************交易历史*****************************
$tpl->set_block("tmp_index", "trade_history_row", "trade_history_rows"); //第一层
$tpl->set_block("trade_history_row", "trade_history_list", "trade_history_lists"); //第二层

$query = "select type,game_name,game_server,game_ID,role_name,state,date from trade_history where from_user = '".$_COOKIE["member_user"]."'";
$tmp_query = mysql_query($query);


$tmp_query_data_count =mysql_query("SELECT COUNT(id) FROM trade_history where from_user = '".$_COOKIE["member_user"]."'"); //统计 数据 的 行数 (也就是有多少条数据)
$query_array_data_count = mysql_fetch_array($tmp_query_data_count); //取出 条数
$data_count = $query_array_data_count[0];

for($i=0;$i<$data_count;$i++) //循环 <tr> 第一层块
{
        $tpl->set_var("trade_history_rows");
        for($j=0;$j<$data_count;$j++) // 第二层块
        {
               
                $query_array = mysql_fetch_array($tmp_query);
                $tpl->set_var("type", $query_array["type"]); //交易类型
                $tpl->set_var("game_name", $query_array["game_name"]); //游戏名称
                $tpl->set_var("game_server", $query_array["game_server"]); //服务器名称
                $tpl->set_var("game_ID", $query_array["game_ID"]); //游戏ID
                $tpl->set_var("role_name", $query_array["role_name"]); //角色名称
                $tpl->set_var("state", $query_array["state"]); //状态
                $tpl->set_var("date", $query_array["date"]); //记录生成时间

                $tpl->parse("trade_history_rows", "trade_history_row", true);
        }
        $tpl->parse("trade_history_lists", "trade_history_list", true);
}
//***************************************交易历史*****************************
[/php]

===================================

index.html块循环 代码片段
<!-- BEGIN trade_history_row -->
<tr>
<!-- BEGIN trade_history_list -->
<td align="center">{type}</td>
<td align="center">{game_name}</td>
<td align="center">{game_server}</td>
<td align="center">{game_ID}</td>
<td align="center">{role_name}</td>
<td align="center">{state}</td>
<td align="center">{date}</td>
<!-- END trade_history_list -->
</tr>
<!-- END trade_history_row -->

==================================

现在出现的效果:


但是MYSQL中有两条数据:




如何让它正常显示呢?
$tpl->set_var("...","...");
这我也已经用了循环 嵌套,但总是最后,我也想用类型 $query_array["type"][$j],但显示出来是个问号。

谢谢各位了!在线等,很急。

[ 本帖最后由 漫无目的 于 2007-7-31 11:04 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2007-08-02 14:51 |只看该作者
<!-- BEGIN trade_history_list -->
<td align="center">{type}</td>
<td align="center">{game_name}</td>
<td align="center">{game_server}</td>
<td align="center">{game_ID}</td>
<td align="center">{role_name}</td>
<td align="center">{state}</td>
<td align="center">{date}</td>
<!-- END trade_history_list -->
不知道这一段是循环个啥?多余

论坛徽章:
0
3 [报告]
发表于 2007-08-03 15:03 |只看该作者
LZ把顺序搞错了!循环应该由内至外。把红色的改掉,蓝色部分互换就OK

$tpl->set_block("tmp_index", "trade_history_row", "trade_history_rows"); //第一层
$tpl->set_block("trade_history_row", "trade_history_list", "trade_history_lists"); //第二层
……
for($i=0;$i<$data_count;$i++) //循环 <tr> 第一层块
{
       $tpl->set_var("trade_history_rows"); 此处应为第二层handler trade_history_lists
        for($j=0;$j<$data_count;$j++) // 第二层块
        {
               
                $query_array = mysql_fetch_array($tmp_query);
                $tpl->set_var("type", $query_array["type"]); //交易类型
                $tpl->set_var("game_name", $query_array["game_name"]); //游戏名称
                $tpl->set_var("game_server", $query_array["game_server"]); //服务器名称
                $tpl->set_var("game_ID", $query_array["game_ID"]); //游戏ID
                $tpl->set_var("role_name", $query_array["role_name"]); //角色名称
                $tpl->set_var("state", $query_array["state"]); //状态
                $tpl->set_var("date", $query_array["date"]); //记录生成时间

               $tpl->parse("trade_history_rows", "trade_history_row", true);
        }
        $tpl->parse("trade_history_lists", "trade_history_list", true);
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP