数组求助?
有一个分类表 无限分类的
有一个内容表
数据要求大概如下
传递一个参数 分类ID
查询该ID下面的6小分类和和属于每个小分类的3条内容
页面循环要求是
<!--
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>
<!--
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);
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号