简易php博客(2)_前台

来源:互联网 发布:网络借贷备案信息披露 编辑:程序博客网 时间:2024/05/17 21:07

index.php

<?phpinclude("head.php");dispHaed("blog display page");if (!empty($_GET['keys'])) {    $key = $_GET['keys'];    $w = " title like '%$key%'";}else{    $w=1;}//引入连接数据库include("connect.php");//总记录数mysql_query('set names utf8');$count = mysql_result(mysql_query("SELECT COUNT(*) FROM ".DB_TBNAME),0);//每页显示$size = 10;//总页数$pagecount = ceil($count/$size);//获取浏览器传来的PAGE值 去除两边空格 转成整数 无则赋值1$page = isset($_GET['page']) ? intval(trim($_GET['page'])) : 1;//如果小于1或大于总页数则等于1if($page < 1) $page = 1;if($page > $pagecount)  $page = $pagecount;//从第几条记录开始显示$begin = ($page - 1) * $size;$sql = mysql_query("SELECT * FROM ".DB_TBNAME." WHERE $w ORDER BY id DESC LIMIT $begin,$size");while($count && $rs = mysql_fetch_array($sql)){    $tmp = strip_tags($rs['contents']);    if(strlen($tmp) > 300)        $text = iconv_substr($tmp,0,150,"utf-8")."...";    else        $text = $tmp;    $commentNum = mysql_result(mysql_query("SELECT COUNT(*) FROM comment WHERE newsid = {$rs['id']}"),0);    echo <<<HTML<div><h4 style="margin-top: 0px;"><a href="view.php?id={$rs['id']}">{$rs['title']}</a></h4></div><!--截取内容展示长度--><div><p style="padding-top: 10px; padding-left: 30px; padding-right: 30px;">{$text}</p></div><div style="float:right;margin-bottom: 10px;"><span>date: {$rs['time']}  |  cilck({$rs['hits']})  |  comment({$commentNum})  </span></div>    <hr style="clear: both;">HTML;}//翻页$last = $page - 1;//前页$next = $page + 1;//后页echo <<<HTML<form method="get" style="margin-top: 20px"><a href="?page={$last}"><前页</a>第{$page}/{$pagecount}页<a href="?page={$next}">后页></a> <input type="text" name="page" size="3" title="跳转到第几页?" style="width:100px;height: 26px;margin-bottom: 0px;"/><input type="submit" value="GO" style="margin-left: 10px;"/></form></div>HTML;include("foot.php");?>
view.php

<?phpinclude("head.php");dispHaed("blog display content");include("connect.php");if (!empty($_GET['id'])) {    $id = $_GET['id'];    $sql ="select * from ".DB_TBNAME."  where id='$id' ";    mysql_query('set names utf8');    $query = mysql_query($sql);    $rs = mysql_fetch_array($query);    $sqlup = "update ".DB_TBNAME." set hits=hits+1 where id='$id'";    mysql_query($sqlup);}if (!empty($_POST['submit'])) {    if ($_SESSION['refresh'] != $_POST['content']) {        $sql = "insert into comment (newsid,usr,email,content,ctime)values({$id},'{$_POST['user']}', '{$_POST['email']}','{$_POST['content']}', now())";        mysql_query('set names utf8');        if (!mysql_query($sql)) {            echo '<p>insert failure!</p>';        }        $_SESSION['refresh'] = $_POST['content'];    }}$u = isset($_SESSION['mng_name']) ? $_SESSION['mng_name'] : '';$t = isset($_SESSION['mng_tag']) ? $_SESSION['mng_tag'] : '';if ($u == "" and $t != 1){    echo <<<HTML        <h3 style="margin-top: 1px;"> {$rs['title']}</h3>HTML;}else{    echo <<<HTML         <h3 style="margin-top: 1px;"> {$rs['title']}<span style="font-size: 12px">     [<a href="./admin/edit.php?id={$id}"><B>edit</B></a>]</span></h3>HTML;}mysql_query('set names utf8');$count = mysql_result(mysql_query("SELECT COUNT(*) FROM comment WHERE newsid = $id"),0);$sql = mysql_query("SELECT * FROM comment WHERE newsid = $id order by ctime desc");echo <<<HTML<span style="float: right;margin-right: 10px;margin-bottom: 10px;">date: {$rs['time']}  |  click num: {$rs['hits']}</span><p style="clear: both; margin: 0 0; "><div style="border-top: solid 1px #eee; margin: 0 0;padding: 30px 20px 20px;">{$rs['contents']}</div></p>HTML;$sql_last ="select * from ".DB_TBNAME." where id<$id order by id desc limit 0,1";$sql_next ="select * from ".DB_TBNAME." where id>$id limit 0,1";$result = mysql_query( $sql_last );if( mysql_num_rows( $result ) ) {    $rs = mysql_fetch_array( $result );    echo <<<HTML    <p>【上一篇】<a href="view.php?id={$rs['id']}">{$rs['title']}</a></p>HTML;} else {    echo <<<HTML    <p>【上一篇】 没有了</p>HTML;}$result = mysql_query( $sql_next );if( mysql_num_rows( $result ) ) {    $rs = mysql_fetch_array( $result );    echo <<<HTML    <p>【下一篇】<a href="view.php?id={$rs['id']}">{$rs['title']}</a></p>HTML;} else {    echo <<<HTML    <p>【下一篇】<span> 没有了</span></p>HTML;}echo <<<HTML<div style="background-color: #eee; width: 750px; height: 25px; padding-top: 5px;border-top: solid 1px #ccc;">    <span style="padding-left: 10px;">查看评论</span></div>HTML;if($count > 0){    while($rs = mysql_fetch_array($sql)) {        if ($u == "" and $t != 1) {            echo <<<HTML            <div style="background-color: #eee;margin: 3px 10px 0px;height: 25px; padding-top: 5px;">                <span style="padding-left: 10px;">用户【{$rs['usr']}】于{$rs['ctime']}评论:</span>            </div>            <div style="margin: 0px 10px 3px;height: 25px; padding-left:20px; padding-top: 8px;background:url('./img/me.png') no-repeat 3px 3px;background-size:30px 30px;">                <span style="padding-left: 20px;">{$rs['content']}</span>            </div>HTML;        }else{            echo <<<HTML            <div style="background-color: #eee;margin: 3px 10px 0px;height: 25px; padding-top: 5px;">                <span style=" float: left; padding-left: 10px;">用户【{$rs['usr']}】于{$rs['ctime']}评论:</span>                <span style="float: right; padding-right: 10px;">[ <a href="./admin/delete.php?id={$rs['id']}&newsid={$id}"><B>delete</B></a> ]</span>                <span style="float: right; padding-right: 10px;">(联系方式:{$rs['email']})</span>            </div>            <div style="margin: 0px 10px 3px;height: 25px; padding-left:20px; padding-top: 8px;background:url('./img/me.png') no-repeat 3px 3px;background-size:30px 30px;">                <span style="padding-left: 20px;">{$rs['content']}</span>            </div>HTML;        }    }}else{    echo <<<HTML    <div style="background-color: #fcfcfc;margin: 3px 10px; height: 30px;padding-top: 10px;">        <span>暂无评论!</span>    </div>HTML;}echo <<<HTML    <div style="background-color: #eee; width: 750px; height: 25px; padding-top: 5px;border-top: solid 1px #ccc;">        <span style="padding-left: 10px;">发表评论</span>    </div>    <SCRIPT language=javascript>    function Checkpost() {        if (myform.user.value=="") {            alert("请填写用户名");            myform.user.focus();            return false;        }        if (myform.title.value.length=="") {            alert("请填写联系邮箱");            myform.title.focus();            return false;        }        if (myform.content.value=="") {            alert("留言不能为空");            myform.content.focus();            return false;        }    }    </SCRIPT>    <div style="margin: 10px 100px;width:550px;">        <form action="#" method="post" name="myform" onsubmit="return Checkpost();">            <input type="hidden" name="token" value=""/>            用户:<input type="text" name="user" value=""/><br/>            邮箱:<input type="text" name="email" value="" /><br/>            内容:<textarea type="text" name="content"  cols="60" rows="9" value="" style="width:500px;"></textarea><br/>            <div style="text-align: center;margin-top: 20px;">            <input type="submit" name="submit" value="发表评论" style="margin: 0px auto;"/>            </div>        </form>    </div></div>HTML;include("foot.php");?>
head.php

<?phpfunction dispHaed($content){    echo <<<HTML    <html>    <head>    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />    <title>简易blog前台测试</title>    <link href="./assets/css/bootstrap-combined.min.css" rel="stylesheet">    <link href="./assets/css/font-awesome.css" rel="stylesheet">    <link rel=stylesheet type="text/css" href="./css/css.css">    <div id="main"><div><h3 style="text-align:center"><br>{$content}</h3><br></div><div style="float:left"><a href="index.php"><B>index</B></a>HTML;    session_start();    $u = isset($_SESSION['mng_name']) ? $_SESSION['mng_name'] : '';    $t = isset($_SESSION['mng_tag']) ? $_SESSION['mng_tag'] : '';    if ($u == "" and $t !=1){        echo <<<HTML        <a href="./admin/index.php"><B>login</B></a>HTML;    }else{        echo <<<HTML        <a href="./admin/index.php"><B>background</B></a>         <a href="./admin/logout.php"><B>logout</B></a>HTML;    }    echo <<<HTML        <br><br></div><div style="float:right"><form action="index.php" method="get" style='align:"right"'><input type="text" name="keys" style=" height:26px; margin-bottom: 0px;" ><input type="submit" name="subs" value="search" style="margin-left: 10px;"></form></div><div style="clear:both;height: 1px;"><hr></div>HTML;}?>
foot.php

<?phpecho <<<HTML<div style="width: 750px; margin:10px auto;"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">  <hr>  <tr>    <td class="care" height="40" align="center" valign="middle">简易blog设计<br>      版权所有:<a href="" target="_blank">chenqy</a> </td>  </tr></table></div></body></html>HTML;?>
效果:





0 0