数组

WBOY
WBOYOriginal
2016-06-13 13:43:46992browse

数组求助?
有一个分类表 无限分类的 
有一个内容表 

数据要求大概如下

传递一个参数 分类ID  
查询该ID下面的6小分类和和属于每个小分类的3条内容

页面循环要求是

HTML code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<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基础差 把自己晕了 

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
$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
菜鸟分少 有说的不明白的地方 请包涵下 


 


------解决方案--------------------
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下的内容
------解决方案--------------------
foreach(from=$name_list item=item)
{
{$item.xxxx}
}
------解决方案--------------------
{% 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] %}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn