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...

$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< /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));

  
$show
$cleannews



";
}
echo "     

";

         


    }
if ($admin==1)
{
echo "
返回

";
}

if ($link)
    {
    echo "


$link
";
     
    }
说明:省略了格式方面的标签,这样看起来思路清晰些,你可要加上啊

以上就介绍了使用PHP制作新闻系统的实现思路,包括了新闻系统方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template