有一个分类表 无限分类的 
有一个内容表 数据要求大概如下传递一个参数 分类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
菜鸟分少 有说的不明白的地方 请包涵下 
 

解决方案 »

  1.   

    foreach($type_idarray as $value) {
      $type_id=$value['type_id'];
      $sql_content="select content_name,content_url from `content` where type_id=$value limit 3";//循环三条ID下的内容
      

  2.   

    好吧 感谢  这个错误 不纠结了我在模板里面该怎么循环呢 乔丹哥哥 模板就类似上面的html代码
      

  3.   

    用foreach/section 循环啊。 去看看看smarty的手册。
      

  4.   


    {% 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%}
    我这样写怎么不对呢 咋出来那么多内容呢
      

  5.   

    你得看你的数组是什么结构。print_r($type_array); print_r($content_array); 
      

  6.   

    最外层那个foreach太大了,直接把里面的循环再循环了几次,如果你不太熟悉,建议将其在php页面就分开成内容,smarty里面别搞这么复杂
      

  7.   

    foreach(from=$name_list item=item)
    {
    {$item.xxxx}
    }
      

  8.   

    本帖最后由 xuzuning 于 2012-03-17 15:02:58 编辑
      

  9.   

    由于我不用 Smarty,代码就不贴了,以免误导。给个链接,应该和你的需求是一样的
    http://www.jb51.net/article/27285.htm
      

  10.   

    print_r($type_array)
    Array ( [0] => Array ( [0] => 北京 [1] => 天安门  [2] => beijing ) [1] => Array ( [0] => 西安 [1] => 兵马俑 [2] => xian ) [2] => Array ( [0] => 上海 [1] => 东方明珠 [2] => shanghai ) )第二个是array()没有取到值 求为什么
      

  11.   

    老大你还是贴上吧 就是数据组合这一块我迷糊了 
    那个链接 我看了下 和我这个有不少区别 
     Smarty部分 我自己来
      

  12.   

    你这就有点无理了,已经跟你说了 由于我不用 Smarty,代码就不贴了,以免误导。
    你形成的数组要符合 Smarty 的要求,不是随便弄个就可以的
      

  13.   

    谢谢老大的链接 忙活了几个小时 数据出来 我再看看 在 Smarty怎么套!
      

  14.   

    数据取出 结构如下格式 Array ( [0] => Array (  [type_id] => 20
    [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%}错误说 无效的属性名称
      

  15.   

    {% foreach name=conname key=type_cont item=cont_name from=[% $type_array[childcategory] %] %}
    似应为
    {% foreach name=conname key=type_cont item=cont_name from=$type_array[childcategory] %}
      

  16.   

    搞定 结贴 谢老大了 
    貌似上面写的也有错应该是 $type_array.childcategory 是字符串下标的应该这样写!老大不差分的 分点其余人哈!