php新闻发布系统发布成功从数据库查询所有数据用表格显示出来03

当弹出发布成功对话框,点击确定按钮进入到
location.href='new_list.php'进入到new_list所执行的php代码
代码如下:
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/3/18
 * Time: 18:17
 * 新闻列表页面
 */
header("content-type:text/html;charset=utf8");
//  数据库名称
$conn = mysqli_connect("localhost", "root", "root", "mynews");
mysqli_set_charset($conn, 'utf8'); //设定字符集
//查询语句
$querySql = "select *from mynews.mynews";
//执行查询操作
$que = mysqli_query($conn, $querySql);
//print_r($que); 多维数组
?>
<!doctype html>
<html>
<head>
    <title>新闻列表展示页面</title>
    <link rel="stylesheet" href="new_list.css">
    <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
    <script src="http://cdn.bootcss.com/jquery/3.0.0/jquery.min.js"></script>
    <script src="http://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>

<body>

<div id="body" class="body container">
    <div class="row">

        <div class="col-md-2"></div>
        <div class="col-md-8 divTable">

                <table class="table-striped" border="2" cellspacing="0">

                    <thead><h3>新闻内容展示页面</h3></thead>
                    <div><a href="new.html">返回发布新闻</a></div>
                    <tr>
                        <th>编号</th>
                        <th>标题</th>
                        <th>内容</th>
                        <th>编辑文章</th>
                        <th>发布时间</th>
                    </tr>
                    <!--因为这里要动态显示 要有for循环 所以要嵌入语言,可以是php也可以是js-->
                    <?php
                    $row = mysqli_fetch_array($que);
                    // $row=mysqli_fetch_row($que);
                    //print_r($row);
                    while ($row = mysqli_fetch_array($que)) {
                        ?>


                        <tr>
                            <td><?php echo $row['_id'] ?></td>
                            <td><?php echo $row ['title'] ?></td>
                            <td><?php echo $row['content'] ?></td>
                            <td>
                                <a href="new_ed.php?id=<?php echo $row['_id'] ?>">修改</a>
                                <a href="new_del.php?id=<?php echo $row['_id'] ?>">删除</a>
                            </td>
                            <td><?php echo $row['3'] ?></td>
                        </tr>

                        <?php
                    }
                    ?>

                </table>
        </div>
        <!-- 一行6列的结束标记-->
        <div class="col-md-2"></div>
    </div>
    <!-- 一行的结束标记-->
</div>
</body>
</html>

//new_list.css代码如下
.body{
    background-color: rgba(128, 128, 128, 0.3);
    border: 1px solid #0000cc;
}

.divTable {
    width: 300px;
    border:2px  solid darkslateblue;
    margin: 5px auto;
    text-align: center;

}

//运行效果如下

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
PHP实例之新闻发布系统 Create TABLE `news` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `p_time` DATETIME NOT NULL , `title` VARCHAR( 80 ) NOT NULL , `detail` TEXT NOT NULL ) TYPE = innodb; create table news(id int not null auto_increment primary key, p_time datetime not null, title varchar(80)not null, detail text not null )type=innodb; 数据库连接:conn.php <? $conn = @mysql_connect('localhost','root','')or die(mysql_error()."不能连接到数据库!"); //连接数据库; $db = mysql_select_db('news',$conn); $page_size = 8; //每页最多显示新闻条数; ?> 添加新闻页面:new.php <? $title="新闻发布系统"; include("inc/header.inc");//头文件 ?> <style type="text/css"> <!-- .STYLE1 {font-size: 12px} .title { font-size: 12px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; font-family: "宋体"; color: #993300; line-height: normal; height: 16px; } .field { font-family: "宋体"; font-size: 12px; color: #993333; } .STYLE2 { font-size: 16px; font-weight: bold; } --> </style> <p align="center" class="STYLE2">PHP+Mysql新闻发布</p> <form action="post.php" method="post" name="frm" id="frm"> <table width="500" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#0066FF"> <tr> <td height="1" bgcolor="#FFFFFF"><span class="STYLE1">标题:</span></td> </tr> <tr> <td height="1" bgcolor="#FFFFFF"><input name="title" type="text" class="title" id="title" size="60" maxlength="80"></td> </tr> <tr> <td height="1" bgcolor="#FFFFFF"><span class="STYLE1">内容: </span></td> </tr> <tr> <td height="1" bgcolor="#FFFFFF"><textarea name="textfield" cols="58" rows="6" class="field"></textarea></td> </tr> <tr> <td bgcolor="#FFFFFF"><input name="submit" type="submit" value="发布"></td> </tr> </table> </form> <? include("inc/navbar.inc");//底部 ?> 新闻处理页面:post.php <? include"conn.php"; $title=htmlspecialchars($_POST['title']); $textfield=htmlspecialchars($_POST['textfield']); $pub_time=date('Y')."-".date('m')."-".date('d')." ".date('H').":".date('i').":".date('s'); $query="insert into news(title,detail,p_time)values ('$title','$textfield','$pub_time')"; $result=mysql_query($query); if($result) { echo "发布成功!<br>"; echo "<a href='list.php'>新闻列表</a> <a href='new.php'>继续发布</a>"; } else { echo mysql_error()."<br>"; echo "发布失败!请<a >返回</a>"; } ?> 新闻列表:list.php <? include "conn.php"; $query = "Select COUNT(*) FROM news"; $result = mysql_query($query); $num = mysql_num_rows($result); $page_count = ceil($num/$page_size); //$offset = ($page_count-1)*$page_size; if(empty($_GET['page'])) { $page = 1; }else { $page = $_GET['page']; if($page<=0) { $page = 1; }else { $page >= $page_count; $page = $page_count-1; } } $query ="Select * FROM `news` orDER BY `id` DESC LIMIT ".($page-1)*$page_count.","."$page_size"; $result = mysql_query($query); ?> <table width="571" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#0066FF"> <tr> <td width="5" bgcolor="#FFFFFF"><div align="center"></div></td> <td width="343" bgcolor="#FFFFFF"><div align="center">标题</div></td> <td width="189" bgcolor="#FFFFFF"><div align="center">时间</div></td> </tr> <?php while($l_result = mysql_fetch_array($result)) { ?> <tr> <td bgcolor="#FFFFFF"><div align="center"><?php echo $l_result['id'];?></div> </td> <td bgcolor="#FFFFFF"><div align="center"><a href="<?php echo "><?php echo $l_result['title'];?></a></div></td> <td bgcolor="#FFFFFF"><div align="center"><a href="<?php echo "><?php echo $l_result['p_time'];?></a></div></td> </tr> <?php } ?> </table><br> <center><a href="new.php">发布信息</a><br></center> <?php //页码显示 for ($i=1;$i<=($page_count-1);$i++){ echo "<a page=".$i.">".$i."</a> "; } //页码显示 ?> 新闻显示页面:view.php <? include "conn.php"; $query = "Select * FROM news where id=".$_GET['id']; $result = mysql_query($query); $v_result = @mysql_fetch_array($result); ?> <table width="60%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#0066FF"> <tr> <td bgcolor="#FFFFFF">标题:</td> </tr> <tr> <td bgcolor="#FFFFFF"><?php echo $v_result['title'];?></td> </tr> <tr> <td bgcolor="#FFFFFF">内容:</td> </tr> <tr> <td bgcolor="#FFFFFF"><?php echo $v_result['detail'];?></td> </tr> <tr> <td bgcolor="#FFFFFF"><a href="list.php">返回</a></td> </tr> </table>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值