[phpBB Debug] PHP Notice: in file /includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
www.dhtmlgoodies.com • View topic - Help with Ajax Poller

Help with Ajax Poller

Moderators: Calcifer, slothy

Help with Ajax Poller

Postby cluster » Sat May 20, 2006 8:08 am


I m having problem with Ajax poller.
ie when i click on vote button it only displays the poll title but does not display the graph. :(
I have changed the ajax-poller-cast-vote-php to ajax-poller-cast-vote-php.php

The database structure is
`poll_id` int(5) NOT NULL default '0',
`poll_quest` varchar(200) NOT NULL default '',
`poll_type` varchar(10) NOT NULL default '',
`poll_valid` varchar(20) NOT NULL default '',
PRIMARY KEY (`poll_id`)
) ;

CREATE TABLE `poll_option` (
`poll_id` int(5) NOT NULL default '0',
`option_id` int(5) NOT NULL default '0',
`option` varchar(100) NOT NULL default '',
`option_weight` int(5) NOT NULL default '0',
PRIMARY KEY (`poll_id`,`option_id`)

CREATE TABLE `poll_vote` (
`vote_id` int(5) NOT NULL auto_increment,
`option_id` int(5) NOT NULL default '0',
`ipAddress` varchar(255) NOT NULL default '',
PRIMARY KEY (`vote_id`)
) ;

the php code :

<form action="<? echo $_SERVER['PHP_SELF']; ?>" onsubmit="return false" method="post">
<div id="mainContainer">
<div id="header"><img src="/images/heading3.gif"></div>
<div id="mainContent">

<div class="poller">

<div class="poller_question" id="poller_question1">
// Retreving poll from database
$res = mysql_query("select * from poll where poll_id=1");
if($inf = mysql_fetch_array($res)){
echo "<p class=\"pollerTitle\">".$inf["poll_quest"]."</p>"; // Output poller title

$resOptions = mysql_query("select * from poll_option where poll_id=1") or die(mysql_error()); // Find poll options, i.e. radio buttons
while($infOptions = mysql_fetch_array($resOptions)){
if($infOptions["defaultChecked"])$checked=" checked"; else $checked = "";
echo "<p class=\"pollerOption\"><input$checked type=\"radio\" value=\"".$infOptions["option_id"]."\" name=\"vote[".$inf["poll_id"]."]\" id=\"pollerOption".$infOptions["option_id"]."\"><label for=\"pollerOption".$infOptions["option_id"]."\" id=\"optionLabel".$infOptions["option_id"]."\">".$infOptions["option"]."</label></p>";
echo $inf["poll_quest"];
echo $infOptions["option"];


<a href="#" onclick="castMyVote(1,document.forms[0])"><img src="images/vote_button.gif"></a>
<div class="poller_waitMessage" id="poller_waitMessage1">
Getting poll results. Please wait...

<div class="poller_results" id="poller_results1">
<!-- This div will be filled from Ajax, so leave it empty --></div>



$optionId = false;

$optionId = $_GET['optionId'];
$optionId = preg_replace("/[^0-9]/si","",$optionId);
$pollId = $_GET['pollId'];
$pollId = preg_replace("/[^0-9]/si","",$pollId);

// Insert new vote into the database
// You may put in some more code here to limit the number of votes the same ip adress could cast.

if($optionId)mysql_query("insert into poller_vote(option_id,ipAddress)values('".$optionId."','".getenv("REMOTE_ADDR")."')");

// Returning data as xml

echo '<?xml version="1.0" ?>';

$res = mysql_query("select poll_id,poll_quest from poll where poll_id='".$pollId."'");
if($inf = mysql_fetch_array($res)){
echo "<pollerTitle>".$inf["poll_quest"]."</pollerTitle>\n";

$resOptions = mysql_query("select option_id,option from poller_option where poll_id='".$inf["poll_id"]."'") or die(mysql_error());
while($infOptions = mysql_fetch_array($resOptions)){
echo "<option>\n";
echo "\t<optionText>".$infOptions["option"]."</optionText>\n";
echo "\t<optionId>".$infOptions["option_id"]."</optionId>\n";

$resVotes = mysql_query("select count(vote_id) from poll_vote where option_id='".$infOptions["option_id"]."'");
if($infVotes = mysql_fetch_array($resVotes)){
echo "\t<votes>".$infVotes["count(vote_id)"]."</votes>\n";
echo "</option>";


echo "No success";


Plz help me!
Posts: 1
Joined: Sat May 20, 2006 7:36 am

Postby Batalf » Sat Jun 17, 2006 12:10 am

Site Admin
Posts: 2160
Joined: Sat Oct 22, 2005 9:38 pm

Return to General questions regarding AJAX scripts

Who is online

Users browsing this forum: No registered users and 7 guests