数组

php中文网
发布: 2016-06-13 13:43:46
原创
1139人浏览过

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

数据要求大概如下

传递一个参数 分类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>
                    <div class="aritcle_card">
                        <a class="aritcle_card_img" href="/ai/1098">
                            <img src="https://img.php.cn/upload/ai_manual/000/000/000/175680092332148.png" alt="怪兽AI数字人">
                        </a>
                        <div class="aritcle_card_info">
                            <a href="/ai/1098">怪兽AI数字人</a>
                            <p>数字人短视频创作,数字人直播,实时驱动数字人</p>
                            <div class="">
                                <img src="/static/images/card_xiazai.png" alt="怪兽AI数字人">
                                <span>44</span>
                            </div>
                        </div>
                        <a href="/ai/1098" class="aritcle_card_btn">
                            <span>查看详情</span>
                            <img src="/static/images/cardxiayige-3.png" alt="怪兽AI数字人">
                        </a>
                    </div>
                
</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] %}
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号