PHP Real-Life News management system to use the bootstrap framework
Just contacted PHP modeled a video on a news management system which also used the bootstrap framework
Write down and tidy up your thoughts.
This is a very simple system, the first is to build a database table.
Mysql>create Database Newsdb
Mysql> CREATE TABLE News (
-ID int unsigned NOT NULL Auto_increment primary key,//This is the ID of the news
Title varchar (+) Not null,//This is the headline of the News
-keywords varchar (+) Not null,//This is the news key word
Author varchar (+) Not null,//This is the author of the News.
-Addtime int unsigned not null,//This is the time to add news
Content text not NULL);//This is the contents of the news
In this way, the database table is built and the page is written below.
First wrote a database configuration file dbconfig.php:
Define (host, "localhost");//Host Name
Define (user, "root");//username
Define (PASS, "");//password
Define (DBNAME, "newsdb");//Database name
?>
Then there is a menu.php file
<title>Html5&bootstrap</title>
News management System
- Browse News
- Press release
After two simple tasks above, it's time to write the homepage http://blog.csdn.net/q114942784/article/details/index.php:
First, import the navigation bar menu.php
And then add a title and a table.
Browse News
Require ("dbconfig.php");
2. Link MySQL, select database
$link = @mysql_connect (Host,user,pass) or Die ("Link Database error! ");
mysql_select_db (DBNAME, $link);
3. Execute the query and return the result set
$sql = "SELECT * from News ORDER by addtime DESC";
$result =mysql_query ($sql, $link);
4. Parse the result set and traverse the output
while ($row =mysql_fetch_assoc ($result)) {
Echo
Echo
Echo
Echo
Echo
Echo
Echo
Echo
Echo
}
5. Releasing the result set
Mysql_free_result (&result);
Musql_close ($link);
?>
1. Import the configuration file
| News ID |
title |
Key Words |
author |
Time |
content |
Operation |
";
| {$row [' id ']} | ";
{$row [' Tilte ']} | ";
{$row [' keywords ']} | ";
{$row [' Author ']} | ";
{$row [' Addtime ']} | ";
{$row [' content ']} | ";
Delete;//The "#" here is just a code name, the back will replace it, because the operation is more complex additions and deletions, so write a separate action.php file
Modify
| ";
"
action.php:
This is a page of data deletion and modification
1. Import the configuration file
Require ("dbconfig.php");
2. Link MySQL and select the database
$link = @mysql_connect (Host,user,pass) or Die ("Database link failed");
mysql_select_db (DBNAME, $link);
3. According to the value of the action, to determine the operation, to execute the corresponding code
Switch ($_get["action"]) {
Case "Add":
1. Get the information you want to add, plus additional information
$tilte =$_post["title"];
$keywords =$_post["keywords"];
$author =$_post["Author"];
$content =$_post["Content"];
$addtime =time ();
2. Filtering of information
3. Stitching the SQL statements and performing the appropriate actions
$sql =insert into News value (NULL, ' ($title) ', ' ($keywords) ', ' ($author) ', $addtime, ' ($content) ');
mysql_query ($sql, $link);
4. Determine whether the success
$id =mysql_insert_id ($link);
if ($id >0) {
echo "
News message added successfully
";
}
else{
echo "
News message Add failed
";
}
Echo ("return");
Echo ("Browse News");
Break
Case "Del":
1. Get the news ID you want to delete:
$id =$_get[' id '];
2. Assemble and delete the SQL statement, and perform the corresponding delete operation
$sql = "Delete from news where id= ($id)";
mysql_query ($sql, $link);
3. Automatically jump to the news browsing screen after deletion
Header ("location:http://blog.csdn.net/q114942784/article/details/index.php");
Break
Case "Update":
1. Get the information you want to modify
$title = $_post[' title '];
$keywords = $_post[' keywords ');
$author = $_post[' author ');
$content = $_post[' content '];
$id = $_post[' id '];
2. Filter the information to be modified (omitted here)
3. Assemble and modify SQL statements and perform modification actions
$sql = "Update news set title=" ($title) ", keywords= ' ($keywords) ', author= ' ($author) ', content= ' ($content) ' where id= ($id )";
Echo $sql;
mysql_query ($sql, $link);
4. Skip to the Browsing interface
Header ("location:http://blog.csdn.net/q114942784/article/details/index.php");
Break
}
4. Close the database link
Mysql_close ("$link");
?>
The following page http://blog.csdn.net/q114942784/article/details/add.php files for adding news:
Press release
Then the edited page edit.php page:
1. Import the configuration file
Require ("dbconfig.php");
2. Connect to MySQL and select a database
$link = @mysql_connect (Host,user,pass) or Die ("Database link failed");
mysql_select_db (DBNAME, $link);
3. Get the ID of the information you want to modify, and assemble to view the SQL statement, execute the query, get the information you want to modify
$sql = "SELECT * from news where id={$_get[' id '}";
$result =mysql_query ($sql, $link);
4. Determine if you have obtained the information you want to modify
if ($result && mysql_num_rows ($result) >0) {
$news =mysql_fetch_assoc ($result);
}else{
Die ("No information is found to be modified");
}
?>
Edit News
Finally, mention, delete and modify the "#" with what instead of
Here in order to humanize some, with the JS code to give a hint
First "#", replaced with Javascript:dodel ({$row ["id"]})
A second "#", with edit.php? id={$row ["id"]} override
At this point, a complete PHP news management system has been basically completed, tomorrow to improve a bit.
http://www.bkjia.com/PHPjc/871191.html www.bkjia.com true http://www.bkjia.com/PHPjc/871191.html techarticle PHP Real-Life News management system used to the bootstrap framework just contact PHP modeled video wrote a news management system which also used the bootstrap framework to write down the idea. ...