Jump to content

poll script result on same page


vikela

Recommended Posts

hi i am still to get this poll result on same spot.i want a poll script that uses the db.

 

<?   
//$dbservertype='mysql';
$servername='myserver';
// username and password to log onto db server
$dbusername='myusername';
$dbpassword='mypasswd';
// name of database
$dbname='mydb';


connecttodb($servername,$dbname,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}

/* Read the session id to
display the poll result link
*/

if(mysql_fetch_object(mysql_query("select s_id from plus_poll_ans where s_id='$s_id'"))){
//echo "<a href=polling/view_poll_result.php>View the poll result</a>";}
echo"<a href=polling/view_poll_result.php onclick=MM_openBrWindow('polling/view_poll_result.php','poll','width=350,height=200')>View Result</a>";}
/* You can keep the parts below inside the else area if you don't want to
show the form for the visitors who have already participated in the poll
*/
$qst_id=2; // Change this ID for a different poll
$query=mysql_fetch_object(mysql_query("select * from plus_poll where qst_id=$qst_id"));
echo "
<form method=post action=poll_displayck1.php>
<input type=hidden name=qst_id value=$qst_id>
<table border='1' cellspacing='0'  width='120' id='AutoNumber1'>
  <tr>
    <td width='100%'> <font face='Verdana' size='2' >$query->qst</font></td>
  </tr>
  <tr>
    <td width='100%' >
    <table border='0' cellspacing='0' width='100%'  cellpadding='0'>
      <tr bgcolor='#f1f1f1'>
        <td width='10%'><input type='radio' value='$query->opt1'  name='opt'></td>
        <td width='90%'><font face='Verdana' size='2' >$query->opt1</font></td>
      </tr>
      <tr>
        <td width='10%'><input type='radio' value='$query->opt2'  name='opt'></td>
        <td width='90%'><font face='Verdana' size='2' >$query->opt2</font></td>
      </tr>
      <tr bgcolor='#f1f1f1'>
        <td width='10%'><input type='radio' value='$query->opt3'  name='opt'></td>
        <td width='90%'><font face='Verdana' size='2' >$query->opt3</font></td>
      </tr>
      <tr>
        <td width='10%'><input type='radio' value='$query->opt4'  name='opt'></td>
        <td width='90%'><font face='Verdana' size='2' >$query->opt4</font></td>
      </tr>
    </table>
    </td>
  </tr>
<tr>
    <td width='100%' bgcolor='#ffff00' align=center>
<font face='Verdana' size='2' ><input type=submit value=Submit></form></td>
  </tr>

</table>
";
/* End of the form displaying the poll question and its four options for selection */
?>



</script>


<center>

<a href="polling/view_poll_result.php">View Results</a><br>
<br>


/show results


connecttodb($servername,$dbname,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}
//////////////////////////////
echo "<font size='2' face='Verdana' color='#000000'> ( Poll ID = 1)</font>";

$qst_id=2; // change this to change the poll

/* Find out the question first */
$fg=mysql_query("select qst from plus_poll where qst_id='$qst_id'");
$row=mysql_fetch_object($fg);

echo "<br><b><br>$row->qst</b><br>"; // display the question
/* for percentage calculation we will find out the total number
of answers ( options submitted ) given by the visitors */
$rt=mysql_num_rows(mysql_query("select ans_id from plus_poll_ans where qst_id=$qst_id"));


/* Find out the answers and display the graph */
$query="select count(*) as no,qst,plus_poll_ans.opt from plus_poll,plus_poll_ans where plus_poll.qst_id=plus_poll_ans.qst_id and plus_poll.qst_id='$qst_id' group by opt ";
$rs=mysql_query($query);
echo "<table cellpadding='0' cellspacing='0' border='0' >";

while($noticia = mysql_fetch_array($rs)){
echo "<tr>
    <td width='40%' bgcolor='#F1F1F1'> <font size='1' face='Verdana' color='#000000'>$noticia[opt]</font></td>";
$width2=$noticia['no'] *50 ;
$ct=($noticia[no]/$rt)*100;
$ct=sprintf ("%01.2f", $ct); // number formating
echo "<td width='10%' bgcolor='#F1F1F1'> <font size='1' face='Verdana' color='#000000'>($ct %)</font></td><td width='50%' bgcolor='#F1F1F1'><img src='graph.jpg' height=10 width=$width2></td>
  </tr>";
echo "<tr>
    <td  bgcolor='#ffffff' colspan=2></td></tr>";


}
echo "</table>";
echo "</font>";


?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.