Hai,

Any one help me to do a PHP poll .......... Please give the logic behind it.... I am new to PHP ....
Please give the logic not code

Regards
Rajeesh

Recommended Answers

All 3 Replies

hello..
i like your way of asking only logic not code...i really appreciate it...

See, if you have so many questions in your site...the you have to create database table for all of those..
if you have a question like:
How much do you like this article...
1.Excellent 2.Good 3.Average 4. Bad
Means in my way the table look like...
table name: tbl_polling
fields: id,question,option1,option2,option3,option4,curdate
then in php code:
you just create a form and question with 4 options with radio buttons..
when user clicks the submit button, then you can update the particular option by incrementing that field by 1..

In this way you can calculate average of particular option and show it at front end...
you can insert particular question by you own or at admin control panel..you can insert many question which you want to put at front end..

If you have any queries on this..Let me know...
thank you...
shanti.

Ok thank you very much.... For your advice.....

But I need to know how we can show the poll result in a graph to visitors...... I know for that we need 3 images ( according to the number of options ) then how we can increase its width .... I mean in which variable ? Is it the values from the database or from the average ??
Once again thanks

or you can fill td with one color and increment that td width...
i have implemented one small example for this...

<?
mysql_connect('localhost','root','1234');
mysql_select_db('mydb');

if($_SERVER['REQUEST_METHOD']=='POST')
{
echo $_POST['rate'];
$t="insert into vote_table(`rate`,`status`) values('".$_POST['rate']."','1')";
$r=mysql_query($t);
$msg="Thank you for your vote...";
}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form name="form1" action="" method="post"> 
<table width="70%" border="0" align="center" cellpadding="1" cellspacing="1">
  <tr>
    <td bgcolor="#CC0099"><table width="100%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
      <tr>
        <td>Please rate it : </td>
      </tr>
      <tr>
        <td>How is this Gift Artical... </td>
      </tr>
      <tr>
        <td align="center"><? if(!empty($msg))echo $msg;?></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><img src="images/stillimage-medium.gif" border="1" /></td>
      </tr>
      <tr>
        <td bgcolor="#CC0099"></td>
      </tr>
      <tr>
        <td align="center">Your Rate:  
          <div align="center">
          1
          <input name="rate" type="radio" value="1" />
          2
          <input name="rate" type="radio" value="2" />
          3
          <input name="rate" type="radio" value="3" />
          4
          <input name="rate" type="radio" value="4" />
        
          5
          <input name="rate" type="radio" value="5" />
        </div></td>
      </tr>
      <tr>
        <td align="center"><input type="submit" name="Submit" value="Rate!!" /></td>
      </tr>
      <tr>
        <td align="center"><label></label></td>
      </tr>
      <tr>
          <td bgcolor="#CC0099"></td>
      </tr>
      <tr>
        <td align="center">Rating Results: </td>
      </tr>
      <tr>
        <td align="center">
		 
		    <?
  $y="select rate from vote_table where status=1 and rate=1;";
  $p=mysql_query($y);
  $n=mysql_num_rows($p);
  $a=0;
  while($row=mysql_fetch_assoc($p))
  {
  
 $i=$row['rate'];
   $a=$a+$i;
  }
   $avg=$a/100;
 $r=$avg*100;
     
  ?>
		    1	->   
		  <table width="100" border="0" cellspacing="0" cellpadding="0">
  <tr>
  
    <td bgcolor="#FF0033" width="<?=$r?>">&nbsp;</td>
	  <td >&nbsp;</td>
  </tr>
 
</table>
    <?
  $y2="select rate from vote_table where status=1 and rate=2";
  $p2=mysql_query($y2);
  $n2=mysql_num_rows($p2);
  $a2=0;
  while($row2=mysql_fetch_assoc($p2))
  {
  
 $i2=$row2['rate'];
   $a2=$a2+$i2;
  }
   $avg2=$a2/100;
 $r2=$avg2*100;
     
  ?>
2  ->
  <table width="100" border="0" cellspacing="0" cellpadding="0">
  <tr>
  
    <td bgcolor="#FF0033" width="<?=$r2?>">&nbsp;</td>
	  <td >&nbsp;</td>
  </tr>
 
</table>
    <?
  $y3="select rate from vote_table where status=1 and rate=3";
  $p3=mysql_query($y3);
  $n3=mysql_num_rows($p3);
  $a3=0;
  while($row3=mysql_fetch_assoc($p3))
  {
  
 $i3=$row['rate'];
   $a3=$a3+$i3;
  }
   $avg3=$a3/100;
 $r3=$avg3*100;
     
  ?>
3  ->
<table width="100" border="0" cellspacing="0" cellpadding="0">
  <tr>
  
    <td bgcolor="#FF0033" width="<?=$r3?>">&nbsp;</td>
	  <td >&nbsp;</td>
  </tr>
 
</table>
    <?
  $y4="select rate from vote_table where status=1 and rate=4";
  $p4=mysql_query($y4);
  $n4=mysql_num_rows($p4);
  $a4=0;
  while($row4=mysql_fetch_assoc($p4))
  {
  
 $i4=$row4['rate'];
   $a4=$a4+$i4;
  }
   $avg4=$a4/100;
 $r4=$avg4*100;
     
  ?>
4  ->
<table width="100" border="0" cellspacing="0" cellpadding="0">
  <tr>
  
    <td bgcolor="#FF0033" width="<?=$r4?>">&nbsp;</td>
	  <td >&nbsp;</td>
  </tr>
 
</table>
    <?
  $y5="select rate from vote_table where status=1 and rate=5";
  $p5=mysql_query($y5);
  $n5=mysql_num_rows($p5);
  $a5=0;
  while($row5=mysql_fetch_assoc($p5))
  {
  
 $i5=$row5['rate'];
   $a5=$a5+$i5;
  }
   $avg5=$a5/100;
 $r5=$avg5*100;
     
  ?>

5->
<table width="100" border="0" cellspacing="0" cellpadding="0">
  <tr>
  
    <td bgcolor="#FF0033" width="<?=$r5?>">&nbsp;</td>
	  <td >&nbsp;</td>
  </tr>
 
</table>

 </td>
      </tr>
      <tr>
        <td align="center">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>
</form>
</body>
</html>

i had lost my table structure....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.