Home >Backend Development >PHP Tutorial >Implementation ideas of using PHP to create a news system
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...
以上就介绍了使用PHP制作新闻系统的实现思路,包括了新闻系统方面的内容,希望对PHP教程有兴趣的朋友有所帮助。