有一个分类表 无限分类的
有一个内容表 数据要求大概如下传递一个参数 分类ID
查询该ID下面的6小分类和和属于每个小分类的3条内容页面循环要求是<div class="ch_type">
<table>
<tr>
<td>小分类的名字</td>
</tr>
<tr>
<td><p>内容1</p>
<p>内容2</p>
<p>内容3</p>
</td>
</tr>
</table>
</div>
php基础差 把自己晕了
$sqltype="select type_name,type_description,type_path,type_id from `type` where type_parent= $type_id limit 6";
$ret=mysql_query($sqltype);
$type_idarray=array();
$type_array=array();
while($rows_type=mysql_fetch_array($ret,MYSQL_ASSOC)){
$arrty=array();
$type_idarray[]=$rows_type['type_id'];小分类ID集合
array_push($arrty,count($arrty)+1,$rows_type['type_name']);//小分类名字
array_push($arrty,count($arrty)+1,$rows_type['type_description']);//小分类简介
array_push($arrty,count($arrty)+1,$rows_type['type_path']);//小分类路径
$type_array=array_pad($type_array,count($type_array)+1,$arrty);
}
$content_array=array();
foreach($type_idarray as $value) {
$type_id=$value['type_id'];
$sql_content="select content_name,content_url from `content` where type_id=$type_id limit 3";//循环三条ID下的内容
$rec=mysql_query($sql_content);
while($rows_cent=mysql_fetch_array($ret,MYSQL_ASSOC)){
$arrz=array();
array_push($arrz,count($arrz)+1,$rowzhuti_tour['content_name']);内容名字
array_push($arrz,count($arrz)+1,$rowzhuti_tour['content_url']);内容路径
$content_array=array_pad($content_array,count($content_array)+1,$arrz);
}}
$tempc_html='type.tpl';模板
$obj_html=FILE_PATH.'/type.html';//生成静态网页路径
$smarty->assign('type_array',$type_array);//小分类的数组
$smarty->assign('content_array',$content_array);//内容的数组
$contentc = $smarty->fetch($tempc_html, null, null, false);
$fulnum=file_put_contents($obj_html,$contentc);
需要用smarty 搞成静态
我上面的好像把数组分开了 弄了半天 没弄出来 怎么才能搞成循环呢 求大牛帮忙改改 万分感谢
麻花藤 1264953078
菜鸟分少 有说的不明白的地方 请包涵下
有一个内容表 数据要求大概如下传递一个参数 分类ID
查询该ID下面的6小分类和和属于每个小分类的3条内容页面循环要求是<div class="ch_type">
<table>
<tr>
<td>小分类的名字</td>
</tr>
<tr>
<td><p>内容1</p>
<p>内容2</p>
<p>内容3</p>
</td>
</tr>
</table>
</div>
php基础差 把自己晕了
$sqltype="select type_name,type_description,type_path,type_id from `type` where type_parent= $type_id limit 6";
$ret=mysql_query($sqltype);
$type_idarray=array();
$type_array=array();
while($rows_type=mysql_fetch_array($ret,MYSQL_ASSOC)){
$arrty=array();
$type_idarray[]=$rows_type['type_id'];小分类ID集合
array_push($arrty,count($arrty)+1,$rows_type['type_name']);//小分类名字
array_push($arrty,count($arrty)+1,$rows_type['type_description']);//小分类简介
array_push($arrty,count($arrty)+1,$rows_type['type_path']);//小分类路径
$type_array=array_pad($type_array,count($type_array)+1,$arrty);
}
$content_array=array();
foreach($type_idarray as $value) {
$type_id=$value['type_id'];
$sql_content="select content_name,content_url from `content` where type_id=$type_id limit 3";//循环三条ID下的内容
$rec=mysql_query($sql_content);
while($rows_cent=mysql_fetch_array($ret,MYSQL_ASSOC)){
$arrz=array();
array_push($arrz,count($arrz)+1,$rowzhuti_tour['content_name']);内容名字
array_push($arrz,count($arrz)+1,$rowzhuti_tour['content_url']);内容路径
$content_array=array_pad($content_array,count($content_array)+1,$arrz);
}}
$tempc_html='type.tpl';模板
$obj_html=FILE_PATH.'/type.html';//生成静态网页路径
$smarty->assign('type_array',$type_array);//小分类的数组
$smarty->assign('content_array',$content_array);//内容的数组
$contentc = $smarty->fetch($tempc_html, null, null, false);
$fulnum=file_put_contents($obj_html,$contentc);
需要用smarty 搞成静态
我上面的好像把数组分开了 弄了半天 没弄出来 怎么才能搞成循环呢 求大牛帮忙改改 万分感谢
麻花藤 1264953078
菜鸟分少 有说的不明白的地方 请包涵下
$type_id=$value['type_id'];$sql_content="select content_name,content_url from `content` where type_id=$value limit 3";//循环三条ID下的内容
{% foreach name=type_name key=name item=name_list from=$type_array %}
<div class="ch_type">
<table>
<tr>
<td>{% $name_list[1] %}</td>
</tr>
<tr>
<td>
{% foreach name=content_name key=content item=content_list from=$content_array %}
<p>{% $content_list[1] %}</p>
{%/foreach%}
</td>
</tr>
</table>
</div>
{%/foreach%}
我这样写怎么不对呢 咋出来那么多内容呢
{
{$item.xxxx}
}
http://www.jb51.net/article/27285.htm
Array ( [0] => Array ( [0] => 北京 [1] => 天安门 [2] => beijing ) [1] => Array ( [0] => 西安 [1] => 兵马俑 [2] => xian ) [2] => Array ( [0] => 上海 [1] => 东方明珠 [2] => shanghai ) )第二个是array()没有取到值 求为什么
那个链接 我看了下 和我这个有不少区别
Smarty部分 我自己来
你形成的数组要符合 Smarty 的要求,不是随便弄个就可以的
[type_name] => 北京旅游
[type_description] => 天安门
[type_path] => beijing
[childcategory] => Array ( [0] => Array ( [content_name] => 天安门 [content_url] => )
[1] => Array ( [content_name] => 天坛 [content_url] => )
[2] => Array ( [content_name] => 颐和园 [content_url] => ) ) )
[1] => Array ( [type_id] => 21
[type_name] => 西安旅游
[type_description] => 兵马俑
[type_path] => xian
[childcategory] => Array ( [0] => Array ( [content_name] => 兵马俑 [content_url] => )
[1] => Array ( [content_name] => 大雁塔 [content_url] => )
[2] => Array ( [content_name] => 华清池 [content_url] => ) ) )
[2] => Array ( [type_id] => 22
[type_name] => 上海旅游
[type_description] => 东方明珠
[type_path] => shanghai
[childcategory] => Array ( [0] => Array ( [content_name] => 东方明珠 [content_url] => )
[1] => Array ( [content_name] => 世博馆 [content_url] => )
[2] => Array ( [content_name] => 外滩公园 [content_url] => shanhai/xxxxxxx.html ) ) ) )smarty模板循环有错误 求指点 {% foreach name=zhuti key=type item=type_array from=$type_array %}
<td><table width="229" height="195px" background="images/tibet_bg.jpg">
<tr>
<td height="25" style="border-bottom-color:#FFFFFF; border-bottom-width:2px; border-bottom-style:solid">{% $type_array[type_name] %}</td>
</tr>
<tr>
<td height="85" align="left">{% $type_array[type_description] %}</td>
</tr>
<tr>
<td>
{% foreach name=conname key=type_cont item=cont_name from=[% $type_array[childcategory] %] %}
<p>{% $cont_name[content_name] %}</p>
{%/foreach%}
</td>
</tr>
</table></td>
{%/foreach%}错误说 无效的属性名称
似应为
{% foreach name=conname key=type_cont item=cont_name from=$type_array[childcategory] %}
貌似上面写的也有错应该是 $type_array.childcategory 是字符串下标的应该这样写!老大不差分的 分点其余人哈!