刚写完实现更新全部新闻列表的意大利式代码(最后连我都不认得了)

我的意大利面条式代码的网站


<?php 

include_once('global.php');
/*
更新全部新闻列表
从make_news_list.php复制代码过来,稍为更改
*/


//$fid=$_GET['fid'];
//$table=$db->selectTable($fid);








//建立一个函数来获取下拉列表中的页数值

function selectPage($allPage,$childclass)
{
$selectpage='';
$index2=bin2hex($childclass);
$url='';


for($p=1;$p<$allPage+1;$p++)
{
 
 $url=$index2.$p.'.htm';
 $selectpage.='<option value='.$url.'>'.$p.'</option>'; 
}
return $selectpage;


}


$count=$db->showCount('newsclass');


for($fid=1;$fid<$count+1;$fid++)
{
$table=$db->selectTable($fid);
//取得父类的名字
$sql_name="select `class` from newsclass where `fid`='$fid'";
$res_name=mysql_query($sql_name);
list($parentclass)=mysql_fetch_row($res_name);




$sql_class="select `class` from $table group by `class` order by id desc";
$res_class=mysql_query($sql_class);


$count_class=0;
$childclass=array();
$child_class='';


while($row_class=mysql_fetch_assoc($res_class))
{

$childclass[$count_class]=$row_class['class'];


$index=bin2hex($childclass[$count_class]);


  //当前的子类为第一个时
if($count_class==0){$url='index.htm';}
//不是第一个时
else{$url=$index.'1.htm';}


$child_class.='<tr><td><a href='.$url.'>'.$childclass[$count_class].'</a></tr></td>';



$count_class++;

}
mysql_free_result($res_class);


/*三个循环
要点:从第一个循环开始,一层一层的去执行
循环太多,连我自己都难以理解了,反正已经实现自己想要的效果
*/
//echo $count_class;






//第一个循环,是通过子类的数目来进行循环
for($i=0;$i<$count_class;$i++)
{
/*下列语句得到子类中的新闻列表的总数*/
//echo $childclass[$i];
$sql_count="SELECT COUNT(*) FROM $table where `class`='$childclass[$i]'";
$res_count=mysql_query($sql_count);
list($recordCount)=mysql_fetch_row($res_count);
mysql_free_result($res_count);


/*通过总数来获取记录数和下标值等*/
$pagesize=15;
$allPage=ceil($recordCount/$pagesize);
//转化了十六进制,每个子类有着不同的名字,所以每个文件目录有着不同的列表索引
$index=bin2hex($childclass[$i]);





  //第二个子循环是生成新闻列表,然后再进行模板替换
for($page=1;$page<$allPage+1;$page++)
{


$startIndex=($page-1)*$pagesize;
$sql="select * from $table where `class`='$childclass[$i]' order by id desc limit $startIndex,$pagesize";
$res=mysql_query($sql);






$titlelist='';


//对记录集进行保存
while($row=mysql_fetch_assoc($res))
{
$path=$row['remark'];
$replace=$table.'/';
$path=str_replace($replace,'',$path);
$title=$row['title'];
$titlelist.='<tr><td><a href='.$path.' target=_blank>'.$title.'</a></td></tr>';



}




  //读取模板文件


//通过已经建立的方法来获取下拉列表中的页数

$selectPage=selectPage($allPage,$childclass[$i]);




$file=file_get_contents('templates/listTmp.htm');
$file=str_replace('{childclass}',$child_class,$file);
$file=str_replace('{titlelist}',$titlelist,$file);
$file=str_replace('{selectPage}',$selectPage,$file);
$file=str_replace('{allpage}',$allPage,$file);
$file=str_replace('{page}',$page,$file);
$file=str_replace('{parentclass}',$parentclass,$file);
$file=str_replace('{childname}',$childclass[$i],$file);


$previouspage=$index.($page-1).'.htm';

$nextpage=$index.($page+1).'.htm';
  


if ($page==1){$previouspage='?';}
if($page==2&&($i==0)){$previouspage='index.htm';}


if ($page==$allPage){$nextpage='?';}




$file=str_replace('{previouspage}',$previouspage,$file);
$file=str_replace('{nextpage}',$nextpage,$file);


$savepath='../admin/'.$table.'/'.$index.$page.'.htm';




//当前的列表是第一个子类,且当前页面为1时
if($page==1&&$i==0) {$savepath='../admin/'.$table.'/'.'index.htm';}
 
file_put_contents($savepath,$file);
 
}

}
}

?>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值