您的位置:首页 > 其它

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

2008-01-03 11:20 537 查看
投票

 include_once("server1.server.php"); #servidor para XAJAX
 $xajax->printJavascript();
?>

    function back() {
      document.getElementById('poll').style.display = 'block';
      document.getElementById('pollresult').style.display = 'none';
      document.getElementById('pollresult').innerHTML = '';
    }
 


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");
?>

  

  
  ">

 
  ">
 

    function onSubmit() {
      xajax_poll(xajax.getFormValues("pollForm"));
      document.getElementById('poll').style.display = 'none';
      document.getElementById('pollresult').style.display = 'block';
    }

服务器端
function poll($formData){
  global $db;
  $tmp="";
  $objResponse = new xajaxResponse();
 
  $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 .="".$poll["title"]."
";
    for ($i = 0, $count = count($pollitems); $i < $count; $i++) {
      $tmp .="".$pollitems[$i]['content'].": ".$pollitems[$i]['count']."";
    }
  $tmp .="".""."";
 
  $objResponse->addAssign("pollresult","innerHTML",$tmp);
  return $objResponse->getXML();
}

数据库的表如下
CREATE TABLE TBL_POLL (
  poll_id int(11) unsigned NOT NULL default '0',
  title varchar(100) NOT NULL default '',
  created_date bigint(20) unsigned NOT NULL default '0',
  user_id int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (poll_id)
) TYPE=MyISAM;
CREATE TABLE TBL_POLLITEM (
  pollitem_id int(11) unsigned NOT NULL default '0',
  poll_id int(11) unsigned NOT NULL default '0',
  content varchar(100) NOT NULL default '',
  count int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (pollitem_id)
) TYPE=MyISAM;
这个例子中,调查的选项只在页面装载时读出,投票后在原地显示最新的投票信息。不需要弹出窗口

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=514436
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: