程序循环后模板赋值为空,求助兄弟们帮我分析下 本帖最后由 wyf23256 于 2011-11-15 15:28:46 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的$consignee_list就是你上面给的数组吗?除了{$consignee.province.region_name} 不显示 其它的有值吗? 其它都显示,毕竟foreach循环的是一个地址表省份字段那个在地址表里是数字,通过类解析对应省份如地址表省份字段值32,通过类getone_region解析到ID=32的为上海,通过foreach输出得到省份不是数字32,而是‘上海’这么说明白么? 明白 你的模板代码没有问题在于你的php代码的 foreach $consignee['province'] = getone_region($consignee['province']);你上面这一句 其实没有改到 $consignee_list 这个数组的具体内容应该是 $consignee_list[$key]['province'] = getone_region($consignee['province']);你在foreach 完 再 print_r($consignee_list); 看下结果 我说的对不对 $consignee_list[$key]['province'] = getone_region($consignee['province']); Array ( [address_id] => 9 [address_name] => [user_id] => 382 [consignee] => 2323123 [email] => [email protected] [country] => 1 [province] => 25 [city] => 321 [district] => 2721 [address] => wqewqewq [zipcode] => 21 [tel] => 13487065213 [mobile] => [sign_building] => [best_time] => [0] => Array ( [province] => Array ( [region_name] => 上海 ) ) ) Array ( [address_id] => 11 [address_name] => [user_id] => 382 [consignee] => [email] => [country] => 1 [province] => 0 [city] => 0 [district] => 0 [address] => [zipcode] => [tel] => [mobile] => [sign_building] => [best_time] => [1] => Array ( [province] => Array ( ) ) ) Array ( [address_id] => 12 [address_name] => [user_id] => 382 [consignee] => 新天地电脑城 [email] => [email protected] [country] => 1 [province] => 13 [city] => 183 [district] => 1568 [address] => 新天地电脑城 [zipcode] => [tel] => 13487065213 [mobile] => [sign_building] => [best_time] => [2] => Array ( [province] => Array ( [region_name] => 湖北 ) ) ) Array ( [country] => 1 [email] => [city] => 0 [3] => Array ( [province] => Array ( ) ) ) 还是不行,怪的很模板调用出来的显示2 0 1,完整的省ID为25 0 13 感觉被截断了样另,我打印出来用 print_r($consignee['province']['region_name']);显示上海,湖北 说明没问题,问题调用到模板上就不行 怪的很楼上兄弟说的我也照做了,道理是有,但就是出不来效果,只好再劳烦各位 foreach ($consignee_list as $key => $consignee) { $consignee['country'] = isset($consignee['country']) ? intval($consignee['country']) : 0; // $consignee['province'] = isset($consignee['province']) ? intval($consignee['province']) : 0; $consignee['city'] = isset($consignee['city']) ? intval($consignee['city']) : 0; $province_list[$region_id] = get_regions(1, $consignee['country']); $city_list[$region_id] = get_regions(2, $consignee['province']); // $consignee['province'] = getone_region($consignee['province']);$consignee_list[$key]['province'] = getone_region($consignee['province']); // print_r($consignee); //exit; $district_list[$region_id] = get_regions(3, $consignee['city']); }print_r($consignee_list);这样 然后贴出你的结果 [我又来求助^_^]如何读取上传压缩包tar.gz里面每个文件名及内容 如何循环一个table并获取每行td中的值 这个功能如何实现? PHP中GD库如何将图片输出至页面? 关于格式化时间的问题,请高手指教 听说php每次为新打开的窗口分配一个SID? 这个简单的小偷程序怎么写啊? 在链接adodb.inc.php时,莫名其妙的出错.... 怎么用socket post数据,模拟form? 有没有人对dba函数库熟? 谁用NetBeans IDE+xdebug 能进行表单调试么? php 点阵画图小集合
除了{$consignee.province.region_name} 不显示 其它的有值吗?
省份字段那个在地址表里是数字,通过类解析对应省份
如地址表省份字段值32,通过类getone_region解析到ID=32的为上海,通过foreach输出得到省份不是数字32,而是‘上海’这么说明白么?
在于你的php代码的 foreach
$consignee['province'] = getone_region($consignee['province']);
你上面这一句 其实没有改到 $consignee_list 这个数组的具体内容
应该是 $consignee_list[$key]['province'] = getone_region($consignee['province']);
你在foreach 完 再 print_r($consignee_list); 看下结果 我说的对不对
还是不行,怪的很
模板调用出来的显示2 0 1,完整的省ID为25 0 13 感觉被截断了样另,我打印出来用 print_r($consignee['province']['region_name']);
显示上海,湖北 说明没问题,问题调用到模板上就不行 怪的很楼上兄弟说的我也照做了,道理是有,但就是出不来效果,只好再劳烦各位
{
$consignee['country'] = isset($consignee['country']) ? intval($consignee['country']) : 0;
// $consignee['province'] = isset($consignee['province']) ? intval($consignee['province']) : 0;
$consignee['city'] = isset($consignee['city']) ? intval($consignee['city']) : 0; $province_list[$region_id] = get_regions(1, $consignee['country']);
$city_list[$region_id] = get_regions(2, $consignee['province']);
// $consignee['province'] = getone_region($consignee['province']);
$consignee_list[$key]['province'] = getone_region($consignee['province']);
// print_r($consignee);
//exit;
$district_list[$region_id] = get_regions(3, $consignee['city']);
}print_r($consignee_list);这样 然后贴出你的结果