当前位置:编程学习 > php >>

实现一个基于Ajax的调查程序

<html>
<head>
<title>投票</title>
<META http-equiv=Content-Language content=zh-cn>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<style type="text/css">
<!--
.poll {font-size: 10pt;display:block}
.pollresult {font-size: 12pt;display:none}
-->
</style>
<?php(做为现在的主流开发语言)
 include_once("server1.server.php(做为现在的主流开发语言)"); #servidor para Xajax(动态网站静态化)
 $xajax(动态网站静态化)->printJavascript();
?>

</head>
<body>

<script language=javascript>
    function back() {
      document.getElementById(poll).style.display = block;
      document.getElementById(pollresult).style.display = none;
      document.getElementById(pollresult).innerHTML = ;
    }
</script> 
<div id=pollresult class=pollresult>

</div>


<?php(做为现在的主流开发语言)


global $db;

$poll = $db->getRow("select * from TBL_POLL order by poll_id desc limit 1");
$poll_id = $poll["poll_id"];
$pollitems = $db->getAll("select * from TBL_POLLITEM where poll_id=$poll_id");
?>
<div id=poll class=poll>
<form id="pollForm" action="javascript:void(null);" onsubmit="onSubmit();">
   <?php(做为现在的主流开发语言) echo $poll["title"]; ?><br>
   <?php(做为现在的主流开发语言) for ($i = 0, $count = count($pollitems); $i < $count; $i++) { ?>
  <input type="radio" style="background-color : #CCCCCC;" name="pollitem" value="<?php(做为现在的主流开发语言) echo $pollitems[$i][pollitem_id] ?>"><?php(做为现在的主流开发语言) echo $pollitems[$i][content] ?><br>
  <?php(做为现在的主流开发语言) } ?>
  <input type="hidden" name="poll_id" value="<?php(做为现在的主流开发语言) echo $poll_id; ?>">
  <input type="submit" value="enter">
</form>
<script language=javascript>
    function onSubmit() {
      xajax(动态网站静态化)_poll(xajax(动态网站静态化).getFormValues("pollForm"));
      document.getElementById(poll).style.display = none;
      document.getElementById(pollresult).style.display = block;
    }
</script>
</div>

</body>
</html>

服务器端

function poll($formData){
  global $db;
  $tmp="";
  $objResponse = new xajax(动态网站静态化)Response();
 
  $poll_id = $formData[poll_id];
  $pollitem_id = $formData[pollitem];
 
  if($pollitem_id > 0 && $poll_id > 0) {
   $db->query("update ".TBL_POLLITEM." set count=count+1 where pollitem_id = $pollitem_id");                 
  }
 
  $poll = $db->getRow("select * from TBL_POLL where poll_id = $poll_id");
  $pollitems = $db->getAll("select * from TBL_POLLITEM where poll_id=$poll_id");
 
 
  $tmp .="<div align=center>".$poll["title"]."</div><br>";
    for ($i = 0, $count = count($pollitems); $i < $count; $i++) {
      $tmp .="<div align=left>".$pollitems[$i][content].": ".$pollitems[$i][count]."</div>";

补充:Web开发 , php ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,