投票管理程序_php基础_脚本之家

我们可以用新闻系统来存储新闻,我们可以对新闻进行添加、删除等操作,这样减少了大家的工作量,为什么不实验一下。
首先,建立一个表。 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; }
第四步,让我们考虑如何将新闻显示出来 //上面已经定义的函数库…
//表格的定义…… centerFONT 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=ALLFONT
SIZE=-2FACE=’georgia’,verdana,Arial,Lucida Sans,Gill SansAll
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=leftFONT
SIZE=-2FACE=’verdana’,Arial,Lucida Sans,Gill
Sans$showbr$cleannews/font/TD ; } echo ; } if ($admin==1) { echo centera
href=admin/index.phpFONT SIZE=-2 FACE=’verdana’,Arial,Lucida Sans,Gill
Sans返回/font/a/center ; } if ($link) { echo centerbrbr$link/center; }
说明:省略了格式方面的标签,这样看起来思路清晰些,你可要加上啊

投票管理程序 表结构 CREATE TABLE poll not null
AUTO_INCREMENT,Poll_Name char ,Poll_Del INT DEFAULT ‘0’ , PRIMARY KEY
CREATE TABLE pollsele not null AUTO_INCREMENT,Pollsele_Name char
,Poll_Del INT DEFAULT ‘0’ , Pollsele_poll_Id INT ,pollsele_num int ,

PRIMARY KEY

poll.php//主程序 $db =mysql_connect(“localhost”, “root”,”391450″);
mysql_select_db(“class”,$db); $sql=”select poll_id,Poll_Name from
poll where poll_del=’1′”; @$result = mysql_query;
$myrow=mysql_fetch_row; echo “

“; echo “

“; echo “$myrow[1]”; $sql=”select Pollsele_Name,pollsele_poll_id
from pollsele where pollsele_del=’0′ and
pollsele_poll_id=’$myrow[0]'”; @$result = mysql_query; echo “

“; echo “

“; while($myrow=mysql_fetch_row { echo “$myrow[0]”; echo ” “;} echo

“;echo “
“; echo “”; echo “

“; echo “

“;echo “

“; echo “

“; mysql_close(); echo “
“; echo “

“; echo “管理”; echo “

“;?>

$db
=mysql_connect(“localhost”, “root”,”391450″);
mysql_select_db(“class”,$db); $sql=”select
poll_id,poll_name,poll_del from poll”; echo “

“; $result=mysql_query; while($my=mysql_fetch_row { echo “

“;echo “

“;echo $my[0];echo “

“; echo “

$my[1]

“; echo “

“;echo $my[2];echo “

“; echo “

“; }echo “

“; ?> if($submit2!=”添加”) { echo “

“; echo “

“; echo “主题:”; echo “”; echo “”; echo “”; echo”

“;} else {$db =mysql_connect(“localhost”, “root”,”391450″);
mysql_select_db(“class”,$db); $sql=”select poll_name from poll where
poll_name=’$title'”; mysql_query; $sql=”insert into poll values”;
mysql_query; echo “

“;} if($submit1!=”有效”&&$submit3!=”删除”) {echo “

“; echo “

“; echo “设置主题:”; echo “”; $db =mysql_connect(“localhost”,
“root”,”391450″); mysql_select_db(“class”,$db); $sql=”select Poll_Id
from poll”; $result = mysql_query; while($myrow=mysql_fetch_row {
echo “$myrow[0]”;} echo “”; echo “”; echo “”; echo “”; echo “

“; } else { if($submit1==”有效”) { $db =mysql_connect(“localhost”,
“root”,”391450″); mysql_select_db(“class”,$db); $sql=”update poll set
Poll_Del=’0′”; $result = mysql_query; $sql=”update poll set
Poll_Del=’1′ where poll_id=’$sele'”; $result = mysql_query; echo “

“;} else {$db =mysql_connect(“localhost”, “root”,”391450″);
mysql_select_db(“class”,$db); $sql=”delete from poll where
poll_id=’$sele'”; $result = mysql_query; $sql=”delete from pollsele
where pollsele_poll_id=’$sele'”; mysql_query; echo “

“;} } ?>

pollsele.php//添加选项 $db =mysql_connect(“localhost”,
“root”,”391450″); mysql_select_db(“class”,$db); $sql=”select
pollsele_id,pollsele_name,pollsele_del,pollsele_num from pollsele
where pollsele_poll_id=’$id'”; echo “

“; @$result=mysql_query; while($my=mysql_fetch_row { echo “

“;echo “

“;echo $my[0];echo “

“; echo “

$my[1]

“; echo “

“;echo $my[2];echo “

“; echo “

“;echo $my[3];echo “

“; echo “

“; }echo “

“; ?> if($submit2!=”添加”) {echo “

“; echo “

“; echo “选项:”; echo “”; echo “”; echo “”; echo”

“;} else {$db =mysql_connect(“localhost”, “root”,”391450″);
mysql_select_db(“class”,$db); $sql=”insert into pollsele
values(”,’$title’,”,’$id’,”)”; mysql_query; echo “

“;} if($submit1!=”有效”&&$submit3!=”无效”) {echo “

“; echo “

“; echo “设置选项:”; echo “”; $db =mysql_connect(“localhost”,
“root”,”391450″); mysql_select_db(“class”,$db); $sql=”select
Pollsele_Id from pollsele where pollsele_poll_id=’$id'”; $result =
mysql_query; while($myrow=mysql_fetch_row { echo “$myrow[0]”;} echo
“”; echo “”; echo “”; echo “”; echo “

“; } else { $db =mysql_connect(“localhost”, “root”,”391450″);
mysql_select_db(“class”,$db); if ($submit1==”有效”) { $sql=”update
pollsele set Pollsele_Del=’0′ where pollsele_id=’$sele'”; $result =
mysql_query;} else { $sql=”update pollsele set Pollsele_Del=’1′ where
pollsele_id=’$sele'”; $result = mysql_query; echo “

“;} ?>

pollsee.php//投票结果

“; echo $title[0]; echo “”; echo “
“; $sql=”select Pollsele_Name,pollsele_num from pollsele where
pollsele_del=’0′ and pollsele_poll_id=’$poll_id'”; @$result =
mysql_query; echo “

“; while($myrow=mysql_fetch_row {echo “

“; echo “

“; echo $myrow[0];echo “

“;echo $myrow[1]; echo “

“;} echo “

“;} else {echo “你不能投空票!!!”;}
?>【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】

发表评论

电子邮件地址不会被公开。 必填项已用*标注