News system
We can use the news system to store news, we can add to the news, delete and other operations, so as to reduce the workload of everyone, why not experiment.
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, set your login information
$database _user_name= "root";
$database _password= "";
$database _name= "News";
$time _offset= "0";
The third step, let us use the things in the following program as a function, save space Ah!
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;
}
Fourth step, let's consider how to show the news
function libraries already defined above ...
The definition of the table ...
<center><font size=5 face= "' Georgia ', Verdana,arial,lucida sans,gill Sans" > $title ";
if ($admin ==1)
{
echo "Admin";
}
echo "-news</font>
</td></tr>
";
$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 n EWS ORDER BY date Desc ";
}
Else
{
$link = "<a href= $REQUEST _url?show_news_sub=all><font size=-2 face=" ' Georgia ', Verdana,arial,lucida Sans, Gill Sans ">all news</font></a>";
$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 "
";
while ($myrow =mysql_fetch_array ($result))
{
$date = $myrow ["N_date"];
$time = $myrow ["N_time"];
$news = $myrow [News];
$n _id= $myrow ["n_id"];
if (Strtoupper ($show _date) = = "Y" && strtoupper ($show _time) = = "Y")
{
$show = $date. " ". $time;
}
else if (Strtoupper ($show _date) = = "Y" && strtoupper ($show _time)!= "Y")
{
$show = $date;
}
if (Strtoupper ($show _date)!= "y" && strtoupper ($show _time) = = "Y")
{
$show = $time;
}
$cleannews = (NL2BR ($news));
<TD align=left><font size=-2 face= "' Verdana ', Arial,lucida sans,gill Sans" > $show <br> $cleannews < /font</td>
";
}
echo "
";
}
if ($admin ==1)
{
echo "
<center><a href=admin/index.php><font size=-2 face= "' Verdana ', Arial,lucida Sans,Gill Sans" > Return < /font></a></center>
";
}
if ($link)
{
echo "<center><br><br> $link </center>";
}
Description: Omit the format of the label, so that looks clearer, you can add AH