/**
* Poll Survey
*
*
* */
Include "islogin.php";
Include ". /conn/config.inc.php ";
/*action Operation initialization */
if (Emptyempty ($_request[' action ')) {
$_request[' action ']= ' list ';
}else {
$_request[' action ']=trim ($_request[' action ');
}
if ($_request[' action ']== ' add ') {
$tpl->assign (' Submitbutton ', ' Add ');
$tpl->assign (' tmess ', ' Add voting options ');
$TPL->assign (' act ', ' Insert ');
$tpl->display (' Admin/addpoll.tpl ');
}elseif ($_request[' action ']== ' insert ') {
$title =$_post[' title ';
$desc =$_post[' desc '];
$addtime =time ();
$poll =$_post[' Poll '];
$sql = "INSERT INTO poll (title,des,addtime) VALUES (' $title ', ' $desc ', ' $addtime ')";
$rs = $db->query ($sql);
$lastid = $db->insert_id ();
foreach ($poll as $v) {
$sql 2= "INSERT into poll_option (pollid,opdata) VALUES (' $lastid ', ' $v ')";
$rs 2= $db->query ($sql 2);
}
if ($rs && $rs 2) {
echo "";
}else{
echo "";
}
}
Voting list
ElseIf ($_request[' action ']== ' Polllist ') {
$sql = "SELECT * from poll ORDER by id DESC";
$rs = $db->query ($sql);
$poll = $db->fetch_array ($rs);
$poll =getpoll ();
$tpl->assign (' poll ', $poll);
$tpl->assign (' tmess ', ' voting list ');
$tpl->display (' Admin/polllist.tpl ');
}
Delete
ElseIf ($_request[' action ']== ' del ') {
$id =$_get[' id '];
$sql = "Delete from poll where id={$id}";
$sql 2= "Delete from poll_option where pollid={$id}";
echo $sql = "Delete from poll INNER JOIN poll_option on poll_option.pollid=poll.id where id={$id}";
$rs = $db->query ($sql);
$rs 2= $db->query ($sql 2);
if ($rs && $rs 2) {
echo "";
}else{
echo "";
}
}
ElseIf ($_request[' action ']== ' edit ') {
$id =intval ($_get[' id ');
$sql = "Select P.id, P.title, P.des, P.addtime, Po.id, Po.pollid, Po.opdata
From poll as P
Left JOIN poll_option as po on p.id = Po.pollid
WHERE p.id ={$id} ";
$sql = "SELECT * from Poll where id={$id}";
$rs = $db->query ($sql);
$row = $db->fetch_array ($rs);
$sql 2= "select* from Poll_option where pollid={$id} ORDER by ID ASC";
$rs 2= $db->query ($sql 2);
$i = 0;
$potion = ";
while ($row 2= $db->fetch_array ($rs 2)) {
$i + +;
$potion. = " ";
if ($i >2) {
$potion. = " ";
}
$potion. = "";
}
$tpl->assign (' pp ', $potion);
$tpl->assign (' Post ', $row);
$tpl->assign (' tmess ', ' updated voting ');
$tpl->assign (' Submitbutton ', ' Update ');
$TPL->assign (' act ', ' Update ');
$tpl->display (' Admin/editpoll.tpl ');
}
Update voting information www.2cto.com
ElseIf ($_request[' action ']== ' update ') {
$id =$_post[' id '];
$title =$_post[' title ';
$desc =$_post[' desc '];
$addtime =time ();
$poll =$_post[' Poll '];
$sql = "Update poll SET title= ' {$title} ', des= ' {$desc} ', Addtime= ' {$addtime} ' where id= ' {$id} '";
$rs = $db->query ($sql);
foreach ($poll as $k = = $v) {
echo "ID: Yes". $k. " The value is: ". $v;
echo "
";
$sql 2= "Update poll_option SET opdata= ' {$v} ' where id= ' {$k} ' and pollid={$id}";
$rs 2= $db->query ($sql 2);
}
if ($rs && $rs 2) {
echo "";
}else{
echo "";
}
}
============== Voting correlation function =================
Get voting information
function Getpoll () {
Global $db;
$sql = "SELECT * from poll ORDER by id DESC";
$rs = $db->query ($sql);
$data =array ();
while ($row = $db->fetch_array ($rs)) {
$data []= $row;
}
return $data;
}
?>
Excerpt from chaojie2009 's column
http://www.bkjia.com/PHPjc/478383.html www.bkjia.com true http://www.bkjia.com/PHPjc/478383.html techarticle ? PHP/** * Poll * * * * * * include islogin.php; include: /conn/config.inc.php; /*action Operation initialization */if (Emptyempty ($_request[action])) {$_request[action]=list;} else {$_ ...