Implementation ideas of using PHP to create a news system
WBOY
Release: 2016-08-08 09:34:00
Original
1339 people have browsed it
We can use the news system to store news, and we can add and delete news. This reduces everyone's workload. Why not experiment with it.
First, create a table.
create table news (
n_id int(255) not null auto_increment,
n_date datetime not null,
news text not null,
PRimary key(n_id)
);
The second step is to set your login information
$database_user_name="root";
$database_passWord="";
$database_name="news";
$time_offset="0";
The third step, let us make the things used in the subsequent program into functions to save space!
function connect_db()
{
// connects to the database
Global $database_user_name, $database_password;
$db=MySQL_connect("localhost",$database_user_name,$database_password);
Return $db;
}
function db_name()
{
// returns the name of the database
Global $database_name;
$db_name=$database_name;
Return $db_name;
}
function get_now()
{
// gets current date and time
$db=connect_db();
$db_name=db_name();
Mysql_select_db($db_name,$db);
$sql="select now() as now";
$result=mysql_query($sql,$db);
$myrow=mysql_fetch_array($result);
$now=$myrow["now"];
Return $now;
}
The fourth step, let’s consider how to display the news
//The function library defined above...
//Definition of table...
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn