Jump to content

need a little direction


kevinritt

Recommended Posts

I thought I could figure this out but I can't. I have a form that captures data from a couple of questions(it's a poll):

<form style="width: 500px; padding: 5px;" action="" method="post"><fieldset>
<legend>2009 Massachusetts Government Survey</legend>
Are you satisfied with the state's governor's performance?<br />
<input name="current" type="radio" value="yes" />Yes<br />
<input name="current" type="radio" value="no" />No<br />
<br />
Will you vote for your current party affiliation in the next election?<br />
<input name="affiliation" type="radio" value="yes" />Yes<br />
<input name="affiliation" type="radio" value="no" />No<br /><br />
How would you rate the performance of the state legislature during the govenor's term thus far?<br />

<select name="rating">
<option value="No opinion">No opinion</option>
<option value="Poor">1:Poor</option>
<option value="Fair">2:Fair</option>
<option value="Adequate">3:Adequate</option>
<option value="Good">4:Good</option>
<option value="Excellent">5:Excellent</option>
</select><br />
<br />
<input name="submit" type="submit" value="Send " />  <input name="Clear" type="reset" />
</form>

and here's the PHP to insert into the MySQL database:

 <?
$current = $_POST['current'];
$affiliation = $_POST['affiliation'];
$rating = $_POST['rating'];

$hostname = "localhost";
$db_user = ""; // database password 
$db_password = ""; // database password 
$database = ""; //database name 


# THIS CODE IS USED TO CONNECT TO THE MYSQL DATABASE 
$db = mysql_connect($hostname, $db_user, $db_password); 
mysql_select_db($database,$db); 

// db connection
if (isset($_REQUEST['submit'])) { 
# insert data 
$sql = "INSERT INTO results(id, question1, question2, question3) values ('', '$current', '$affiliation', '$rating')"; 

if($result = mysql_query($sql ,$db)) { 
echo 'Your poll was entered'; 
} else { 
echo "ERROR: ".mysql_error(); 
} 
} else { 
?>

What I'm trying to do is get the results from each question. For example, I would like to show "The current results for Question 1 are 23 Yes, 54 No" where the quantities of yes and no are pulled from the database. I just can't seem to figure the logic. Any help would be appreciated

Link to comment
Share on other sites

for question1 you can use

SELECT question1, count(*) num FROM result GROUP BY question1

and so on

If I just wanted the number of 'yes' responses, would I add WHERE question1 = 'yes' to that so it would be

SELECT question1, count(*) num FROM result WHERE question1 = 'yes' GROUP BY question1

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.