The idea of using PHP to make news system

Source: Internet
Author: User
Tags date
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




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.