We can use the message system to store messages. we can add, delete, and hold messages, which reduces the workload of everyone. First, create a table. Createtablenews (n_idint (255) notnullauto_ I
We can use the message system to store messages. we can add, delete, and hold messages, which reduces the workload of everyone.
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)
);
Step 2: Set your login information
$ Database_user_name = 'root ';
$ Database_password = '';
$ Database_name = 'news ';
$ Time_offset = '0 ';
Step 3: Let's make the things used by the subsequent programs into functions and save time!
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;
}
Step 4: Let's consider how to display messages
// The function library defined above...
// Table definition ......
$ Title ';
If ($ admin = 1)
{
Echo 'admin ';
}
Echo '-News
';
$ Db = connect_db ();
$ Db_name = db_name ();
Mysql_select_db ($ db_name, $ db );
If ($ show_news_sub)
{
$ Show_news = $ show_news_sub;
}
If (! Ereg ('([0-9] {'. strlen ($ show_news). '})', $ show_news ))
{
$ Show_news = 'all ';
}
If (strtoupper ($ show_news) = 'all ')
{
$ SQL = 'SELECT date_format (n_date, '% m/% d/% Y') as n_date, date_format (n_date,' % H: % I ') as n_time, news, n_date as date from news order by date desc ';
}
Else
{
$ Link = 'All news ';
$ SQL = 'SELECT date_format (n_date, '% m/% d/% Y') as n_date, date_format (n_date,' % H: % I ') as n_time, news, n_date as date from news order by n_date desc limit $ show_news ';
}
$ Result = mysql_query ($ SQL, $ db );
$ Num_rows = mysql_num_rows ($ result );
If ($ num_rows! = 0)
{
Echo'