|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
兴趣可能会慢慢消亡,所以适当培养兴趣会激发自己无线的乐趣,有了乐趣,编程有啥难的。旧事体系 咱们可以用旧事体系来存储旧事,咱们可以对旧事停止添加、删除等操作,如许削减了人人的任务量,为何不实行一下。
起首,创立一个表。
create table news (
n_id int(255) not null auto_increment,
n_date datetime not null,
news text not null,
primary key(n_id)
);
第二步,设置你的上岸信息
$database_user_name="root";
$database_password="";
$database_name="news";
$time_offset="0";
第三步,让咱们把前面法式用到的器材作成函数,节俭篇幅啊!
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;
}
第四步,让咱们思索若何将旧事显示出来
//下面已界说的函数库...
//表格的界说......
<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 news 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">前往</font></a></center>
";
}
if ($link)
{
echo "<center><br><br>$link</center>";
}
申明:省略了格局方面的标签,如许看起来思绪明晰些,你可要加上啊
告诉你了一个方式,但是缺少努力这一环节,那也是白搭。 |
|