1、今日完成任务:
(1)后端新闻模块的新闻列表显示以及添加、修改和删除操作。
(2)前端新闻页面完成与后台数据库的绑定显示新闻列表,及详情页。
2、核心代码
<tbody> <?php foreach ($rows as $key=>$value){?> <tr class="text-c"> <td><input type="checkbox" value="" name=""></td> <td><?php echo $rows[$key]['newsId']?></td> <td class="text-l"><u style="cursor:pointer" class="text-primary" onClick="article_edit('查看','article-zhang.html','<?php echo $rows[$key]['newsId']?>')" title="查看"><?php echo $rows[$key]['newsTitle']?></u></td> <td><?php if($rows[$key]['newsType']==0){echo "网站公告";}else{echo "行业新闻";}?></td> <td><?php if($rows[$key]['newsType']==0){echo "网站公告";}else{echo "行业新闻";}?></td> <td><?php echo $rows[$key]['newsTime']?></td> <!-- <td>21212</td> --> <td class="td-status"> <span class="label label-success radius">已发布</span> </td> <td class="f-14 td-manage"> <a style="text-decoration:none" onClick="article_stop(this,'<?php echo $rows[$key]['newsId']?>')" href="javascript:;" title="下架"> <i class="Hui-iconfont"></i> </a> <a style="text-decoration:none" class="ml-5" onClick="article_edit('新闻编辑','article-add.php?newsId=<?php echo $rows[$key]["newsId"]?>','<?php echo $rows[$key]['newsId']?>')" href="javascript:;" title="编辑"> <i class="Hui-iconfont"></i> </a> <a style="text-decoration:none" class="ml-5" onClick="article_del(this,'<?php echo $rows[$key]['newsId']?>')" href="javascript:;" title="删除"><i class="Hui-iconfont"></i> </a> </td> </tr> <?php }?> </tbody> </table> <?php }else{?> <p>暂无新闻公告</p> <?php }?>
<?php require_once '../function.php'; $newsId=$_POST['newsId']; $newsTitle=$_POST['newsTitle']; $newsType=$_POST['newsType'];//分类 $newsSummary=$_POST['newsSummary']; $newsAuthor=$_POST['newsAuthor']; $newsContent=$_POST['newsContent']; //图片信息 $info=$_FILES["file"]; if($_GET['newsId']!=0){ //修改 $sql="update news set newsType='$newsType',newsTitle='$newsTitle',newsSummary='$newsSummary',newsContent='$newsContent',newsAuthor='$newsAuthor' where newsId=$newsId;"; $result=oper($sql); if($result){ echo "<script>"; echo 'parent.location.href="article-list.php";'; echo "parent.layer.closeAll();"; echo "</script>"; }else{ echo "fail"; } }else{ //添加 $sql="insert into news(newsType,newsTitle,newsSummary,newsContent,newsAuthor,newsTime,newsStatus)values($newsType,'$newsTitle','$newsSummary','$newsContent','$newsAuthor',NOW(),0);"; $result=oper($sql); if($result){ echo "<script>"; echo 'parent.location.href="article-list.php";'; echo "parent.layer.closeAll();"; echo "</script>"; }else{ echo "fail"; } } ?>
<?php //新闻列表 require_once 'function.php'; //网站公告 $sqlNotice="select * from news where newsType=0;"; $rowsNotice=sel($sqlNotice); //新闻行情 $sqlNews="select * from news where newsType=1;"; $rowsNews=sel($sqlNews); ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>新闻-客车网上售票系统</title> <link rel="stylesheet" type="text/css" href="css/base.css"/> <link rel="stylesheet" type="text/css" href="css/others.css"/> </head> <body> <!--头部--> <div class="header"> <div class="container clear"> <div class="left"><a href="index.html"><img src="img/logo_pc.png"/></a></div> <div class="right clear"> <ul class="nav left clear"> <li><a href="index.html">首页</a></li> <li><a href="ticketsOnline.html">在线订票</a></li> <li class="active"><a href="newsList.php">新闻公告</a></li> <li><a href="leftMessage.html">留言中心</a></li> <li><a href="userInfo.html">个人中心</a></li> </ul> <div class="right btns-links"> <a href="login.html">登录</a> <a href="register.html">注册</a> </div> </div> </div> </div> <!--新闻--> <div class="news-box"> <div class="container clear"> <div class="left main"> <h3>网站公告</h3> <?php if($rowsNotice){?> <ul> <?php foreach ($rowsNotice as $key=>$value){?> <li><a href="newsDetail.php?id=<?php echo $rowsNotice[$key]["newsId"]?>"><?php echo $rowsNotice[$key]["newsTitle"]?></a> <span class="news-time"><?php echo explode(" ", $rowsNotice[$key]['newsTime'])[0]?></span> </li> <?php }?> </ul> <?php }else{?> <p>暂无公告</p> <?php }?> </div> <div class="right aside"> <h3>行业新闻</h3> <?php if($rowsNews){?> <ul> <?php foreach ($rowsNews as $key=>$value){?> <li><a href="newsDetail.php?id=<?php echo $rowsNews[$key]["newsId"]?>"><?php echo $rowsNews[$key]["newsTitle"]?></a> </li> <?php }?> </ul> <?php }else{?> <p>暂无新闻</p> <?php }?> </div> </div> </div> <!--优势--> <div class="register-advantage"> <div class="container"> <ul class="clear"> <li class="clear"> <div class="advantage-img left"><img src="img/icon_pinpaibaozheng.png"/></div> <div class="left"> <h4>品牌保证</h4> <p>提供正规的购票服务</p> </div> </li> <li class="clear"> <div class="advantage-img left"><img src="img/icon_kuaisufankui.png"/></div> <div class="left"> <h4>快速反馈</h4> <p>第一时间短信通知</p> </div> </li> <li class="clear"> <div class="advantage-img left"><img src="img/icon_fangbiankuaijie.png"/></div> <div class="left"> <h4>方便快捷</h4> <p>车站直接取票上车</p> </div> </li> <li class="clear"> <div class="advantage-img left"><img src="img/icon_zhifufangbian.png"/></div> <div class="left"> <h4>支付方便</h4> <p>支付宝微信</p> </div> </li> </ul> </div> </div> <!--底部--> <div class="register-footer"> <p>客车网上售票系统官方电话 400-100-1234 0371-1234567 客车网上售票信息公示</p> <p>客车网上售票系统 Copyright©2020-2030 版权所有 XXXXXX网络科技有限公司 豫ICP备15030935号-1</p> </div> </body> </html>