zoukankan      html  css  js  c++  java
  • 5月5 新闻练习题

    1)查看新闻页面-----主页面:zhu.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    
    <body>
    <h1>主页面</h1>
    <table width="100%" border="1" cellpadding="0" cellspacing="0">
    <tr>
    <td>id</td>
    <td>title</td>
    <td>author</td>
    <td>source</td>
    <td>content</td>
    <td>time</td>
    <td>update</td>
    <td>delete</td>
    </tr>
    
    <?php
    $db = new MySQLi("localhost","root","","newssystem");
    !mysqli_connect_error() or die("连接失败");
    $sql = "select * from news";
    $result = $db->query($sql);
    $attr = $result->fetch_all();
    if($result)
    {
    	foreach($attr as $v)
    	{
    		echo "<tr>
    			  <td>{$v[0]}</td>
    			  <td>{$v[1]}</td>
    			  <td>{$v[2]}</td>
    			  <td>{$v[3]}</td>
    			  <td>{$v[4]}</td>
    			  <td>{$v[5]}</td>
    			  <td>
    			  <a href='xiugai.php?id={$v[0]}'>修改</a>
    			  </td>
    			  
    			  <td>
    			  <a href='shanchu.php?id={$v[0]}'>删除</a>
    			  </td>
    		      
    			  </tr>";	
    	}	
    }
    ?>
    </table>
    
    <div><a href="add.php">添加数据</a></div>
    
    </body>
    </html>
    

    2)发布新闻页面-----添加内容:add.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <style type="text/css">
    .anniu
    {
    	margin-left:200px;
    	float:left;}
    
    </style>
    </head>
    
    <body>
    <h1 style="margin-left:180px">发布新闻</h1>
    <form action="addchuli.php" method="post">
    <div>标题:<input type="text" name="title" style="400px; height:30px"/></div><br />
    <div>作者:<input type="text" name="author" style="180px; height:30px" /></div><br />
    <div>来源:<input type="text" name="source" style="180px; height:30px" /></div><br />
    <div>内容:<textarea name="content" cols="80" rows="10"></textarea></div><br />
    
    <div class="anniu"><input type="submit" value="提交" /></div>
    
    
    <div class="anniu" style="margin-left:20px"><a href="zhu.php"><input type="button" value="查看" />
    </a>
    </div>
    
    </form>
    
    </body>
    </html>
    

      页面显示效果:

    3)发布新闻-----添加出来:addchuli.php

    <?php
    
    	//$id = $_POST["id"];
    	$title = $_POST["title"];
    	$author = $_POST["author"];
    	$source = $_POST["source"];
    	$content = $_POST["content"];
    	$time = date("Y-m-d",time());
    
    	
    	$db = new MySQLi("localhost","root","","newssystem");
    	$sql = "insert into news values('','{$title}','{$author}','{$source}','{$content}','{$time}')";
    	echo $sql;
    	$result = $db->query($sql);
    	if($result)
    	{
    		header("location:zhu.php");
    	}
    	else
    	{
    		echo "添加失败";	
    	}
    

      

    4)删除新闻页面-----删除对象:shanchu.php   

    <?php
    
    	$id = $_GET["id"];
    	
    	$db = new MySQLi("localhost","root","","newssystem");
    	$sql = "delete from news where id ='{$id}'";
    	$result = $db->query($sql);
    	if($result)
    	{
    		header("location:zhu.php");	
    	}
    	else
    	{
    		echo "删除失败";	
    	}
    

      

     修改新闻页面-----修改页面:xiugai.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <style type="text/css">
    .anniu
    {
    	margin-left:200px;
    	float:left;}
    
    </style>
    
    </head>
    
    <body>
    <h1 style="text-align:center">修改新闻</h1>
    <?php
    $id = $_GET["id"];
    $db =new MySQLi("localhost","root","","newssystem");
    $sql = "select * from news where id='{$id}'";
    $result = $db->query($sql);
    $arr = $result->fetch_row();
    
    
    ?>
    <form action="xiugaichuli.php" method="post">
    <div>代号:<input type="hidden" name="id" value="<?php echo $arr[0] ?>" /></div><br />
    
    <div>标题:<input type="text" name="title" style="400px; height:30px" value="<?php echo $arr[1] ?>"/></div><br />
    <div>作者:<input type="text" name="author" style="180px; height:30px" value="<?php echo $arr[2] ?>"/></div><br />
    <div>来源:<input type="text" name="source" style="180px; height:30px" value="<?php echo $arr[3] ?>"/></div><br />
    <div>内容:<textarea name="content" cols="80" rows="10" value=""><?php echo $arr[4] ?></textarea></div><br />
    
    
    <div class="anniu"><input type="submit" value="修改" /></div>
    
    <div class="anniu" style="margin-left:20px"><a href="zhu.php"><input type="button" value="查看" />
    </a>
    </div>
    
    </form>
    
    </body>
    </html>
    

      

    修改时的页面显示:

    修改处理新闻页面-----修改处理:xiugaichuli.php

    <?php
    
    	$id = $_POST["id"];
    	$title = $_POST["title"];
    	$author = $_POST["author"];
    	$source = $_POST["source"];
    	$content = $_POST["content"];
    	$time = date("Y-m-d",time());
    
    	$db = new MySQLi("localhost","root","","newssystem");
    	$sql = "Update news set title='{$title}',author='{$author}',source='{$source}',content='{$content}',time='{$time}' where id='{$id}'";
    	$result = $db->query($sql);
    	if($result)
    	{
    		header("location:zhu.php");	
    	}
    	else
    	{
    		echo "修改失败";	
    	}
    

      

    以上是对于新闻内容添加,修改,删除的练习题

  • 相关阅读:
    并查集_贪心_求无向图最短连通路径_最小生成树(kruskal)
    01背包&&完全背包_顺序枚举和逆序枚举的问题_一维数组
    week7_简单题_C_水题_hdu_5578+F_贪心_hdu_5583
    计量经济学_大纲
    概率专题_概率/ 数学_基础题_ABEI
    动态规划_01背包_从Dijikstra和Floyd入手,彻底理解01背包
    动态规划_基础_最长公共子序列_多种方法_递归/dp
    动态规划_基础_分治思想_从归并排序到任意子区间序列求和_滑动窗口+递推
    分治思想_归并排序_各种写法和思路(待续)
    递归基础_整数划分类问题_ 多状态转移复杂递推
  • 原文地址:https://www.cnblogs.com/Duriyya/p/5465084.html
Copyright © 2011-2022 走看看