这是本人根据自己学习PHP技术页面静态化的过程所写的学习笔记,希望能够对大家有所帮助。 1、基本思想 (1)当我们添加或者更新新闻的时候,同步的创建或更新html页面,解决实时性问题,将生成的html文件的路径放在数据库; (2)设计一个模版文件,通过模版
这是本人根据自己学习PHP技术页面静态化的过程所写的学习笔记,希望能够对大家有所帮助。
1、基本思想
(1)当我们添加或者更新新闻的时候,同步的创建或更新html页面,解决实时性问题,将生成的html文件的路径放在数据库;
(2)设计一个模版文件,通过模版创建静态页面;
(3)以后每次直接访问html静态页面;
2、数据库沿用上面的数据库结构,数据最好清空
3、代码
news_list.php(新闻列表页面)<?php //新闻列表 //查询数据库,获取信息=>SqlHelper.class.php $conn = mysql_connect("localhost", "root", "root"); if (!$conn) { die("连接失败"); } mysql_select_db("static_pages_news", $conn); mysql_query("set names utf8"); $sql = "select * from news order by id"; $res = mysql_query($sql); header("content-type:text/html;charset=utf-8"); echo "<h1 id="新闻列表">新闻列表</h1>"; echo "<a href="add_news.html">添加新闻</a><hr>"; echo "
id | 标题 | 查看新闻 | 修改新闻 |
{$row['id']} | {$row['title']} | 查看详情 | 修改详情 |
add_news.html(添加新闻页面)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>添加新闻</title>
update_newsui.php(修改新闻页面)
<?php //接受要修改的新闻的ID $id = $_GET['id']; //通过id从数据库中获取新闻信息 $conn = mysql_connect("localhost", "root", "root"); if (!$conn) { die("连接失败"); } mysql_select_db("static_pages_news", $conn); mysql_query("set names utf8"); $sql = "select * from news where id = $id"; $res = mysql_query($sql); if ($row = mysql_fetch_assoc($res)) { echo "<form action='newsAction.php' method='post'>"; echo "<input type="hidden" name="oper" value="update">"; echo "<input type="text" name="id" value="{$row['id']}" readonly><br>"; echo "<input type="text" name="title" value="{$row['title']}"><br>"; echo "<textarea cols="50" rows="10" name="content">{$row['content']}</textarea><br>"; echo "<input type="submit" value="修改">"; echo "<input type="reset" value="重置"><br>"; echo "

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1
Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
