Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
creating a survey form
Old 01-19-2009, 09:40 AM creating a survey form
Junior Talker

Posts: 4
Name: stubby
Trades: 0
need help.. i am doing a survey. i have a problem inserting the values of the list/menu values in the database..

here is my sample form


survey1 ()delighted ()satisfied ()disapponted
survey2 ()delighted ()satisfied ()disapponted
survey3 ()delighted ()satisfied ()disapponted


can you send me a sample code on this
thanks in advance..
stubbykiller is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-19-2009, 10:52 AM Re: creating a survey form
anderswc's Avatar
Super Talker

Posts: 132
Name: Will Anderson
Location: Terre Haute, IN
Trades: 0
well, I would probably modify some poll software to fit my needs but meh.

you'll probably want a table for each survey. It must include an ID and name at minimal. You could also include information like a description, who can vote, etc, but we'll start simply. So here's the first table's schema.

SURVEY(id, title)

Next we need a table to store questions. Each question needs to be associated with a survey, have it's own ID, and a title (or question).

QUESTION(id, survey_id, scale_id, title)

Next we need answer scales to associate with questions (for example, delighted/satisfied/disappointed). These will need an ID and description at the least.

SCALE(id, title)

Now we need a table for possible answers. Each answer should store it's scale id and an id, as well as a title and probably an order or value indicator (to say delighted is better than satisfied for example).

SCALE_VALUES(id, scale_id, title, value)

Now we need a table to associate questions with answer scales. it should have a question id and a scale id.

QUESTION_SCALE(question_id, scale_id)

Since each survey can have multiple questions, we need to group the answers into 'result' groups. this allows us to associate answers with each other. We need an id, a survey_id, and the submitter's IP (could also be username if you've got a login interface).

RESULT(id, survey_id, IP)

Now we need a place to store answers. this should have an answer id, question id and scale value (what the actual answer was). We also need to store what result group this answer is in.

ANSWER(id, result_id, question_id, value)

So that outlines a very basic schema for your database. Now here are a couple of SQL queries you'd use to do things with the DB.

add a scale called 'satisfaction'
Code:
INSERT INTO SCALE(id, title)
VALUES(1, 'satisfaction')
add values to scale 'satisfaction'

Code:
INSERT INTO SCALE_VALUE(id, scale_id, title, value)
VALUES(1, 1, 'delighted',1);
INSERT INTO SCALE_VALUE(id, scale_id, title, value)
VALUES(1, 2, 'delighted',2);
INSERT INTO SCALE_VALUE(id, scale_id, title, value)
VALUES(1, 3, 'delighted',3);
create a survey called 'survey1'
Code:
INSERT INTO SURVEY(id, title)
VALUES(1, 'survey1')
add a question called 'satisfaction level' to 'survey1'
Code:
INSERT INTO QUESTION(id, survey_id, scale_id, title)
VALUES(1, 1, 1, 'satisfaction level'
add a survey result/answer set (here we're answering 'delighted'.
Code:
INSERT INTO RESULT(id, survey_id, IP)
VALUES(1, 1, 127.0.0.1);
INSERT INTO ANSWER(id, result_id, question_id, value)
VALUES(1, 1, 1, 1)
note that we could have multiple questions in a survey, so we might need to run the second part of that query multiple times.

Now to view the results of the survey you could run several queries.

how many submissions to survey1?
Code:
SELECT count(RESULT.id)
FROM SURVEY JOIN RESULT ON SURVEY.id = RESULT.survey_id
WHERE SURVEY.title = 'survey1'
how many people gave each answer in 'survey1'
Code:
SELECT count(ANSWER.id), QUESTION.title, SCALE_VALUE.title
FROM SURVEY JOIN RESULT ON SURVEY.id = RESULT.survey_id JOIN ANSWER ON RESULT.id = ANSWER.result_id JOIN QUESTION ON ANSWER.question_id = QUESTION.id JOIN SCALE_VALUE ON ANSWER.value = SCALE_VALUE.id
WHERE SURVEY.id = 'survey1'
GROUP BY RESULT.id, QUESTION.title, SCALE_VALUE.title
This outlines the database structure you're likely to need. Of course you'll need a bit of PHP still to pull this off, but with a good data structure beneath, you should have a much easier time.

I have to go now, but if I get a chance later I'll come back to outline some of what you'll need to do on the PHP side.

[note: SQL code totally untested. should work, but no garantees ]
__________________
Will Anderson

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
anderswc is offline
Reply With Quote
View Public Profile Visit anderswc's homepage!
 
Old 01-19-2009, 11:49 AM Re: creating a survey form
Junior Talker

Posts: 4
Name: stubby
Trades: 0
ei dude. thanks for the help ei.. yup i know how to use sql.. hehe..

il just post what i have done.. having trouble with looping the checkboxes and list/menu.. here's my code..

<?php
include "conn.php";

$sql = "select * from category";
$result = mysql_query($sql) or die(mysql_error());

if(isset($_POST['Post']))
{
$ctrl_no = $_POST['ctrl_no'];
$cat_id = $_POST['cat_id'];
$dept_id= $_POST['dept_id'];
$score = $_POST['score'];

if(empty($ctrl_no))
{
$raise_error = 'Control No. must not be empty!';
}
else
{
for($i=0;$i<count($dept_id);$i++)
{
$sql = "insert into comment_det (ctrl_no, cat_id, dept_id, comment_date, score_id)
values('$ctrl_no', '$cat_id[$i]', '$dept_id[$i]', NOW(), '$score[$i]')";
$res_ins = mysql_query($sql) or die(mysql_error());

}
}


/*$sql = "insert into comment_det (ctrl_no, cat_id, dept_id, comment_date, score_id)
values('$ctrl_no', '$cat_id', '$dept_id', NOW(), '$score')";
$res_ins = mysql_query($sql) or die(mysql_error());*/
//end else



}//if(isset($_POST['Post'])

echo $raise_error;
?>

<!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=utf-8" />
<title>Untitled Document</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="800" border="1" cellpadding="0" cellspacing="0">
<form id="form1" name="form1" method="post" action="main.php">
<tr>
<td width="132">Control No.:</td>
<td width="144">
<input type="text" name="ctrl_no" id="ctrl_no" /> </td>
<td width="183">&nbsp;</td>
<td width="155">&nbsp;</td>
<td width="174">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<?php while($r_cat = mysql_fetch_assoc($result)) { ?>
<tr>
<?php $ctr = count($dept_id);?>
<td><input type="checkbox" name="dept_id[]" id="dept_id[]" value="<?php echo $r_cat['cat_id'];?>"
<?php for($x=0;$x<=$ctr;$x++)
{
if($dept_id[$x] == $r_cat['cat_id'])
{
$checked = "checked";
}
}//end for
?>
/></td>
<td><?php echo $r_cat['cat_name'];?>
<input name="cat_id[]" type="hidden" id="cat_id" value="<?php echo $r_cat['dept_id'];?>" /></td>
<td>
<select name="score[]" id="score[]">
<option value="" selected="selected">-select-</option>
<option value=" 3" <?php if($score == 3) echo "selected";?>>Delighted</option>
<option value="1.5" <?php if($score == 1.5) echo "selected";?>>Satisfied</option>
<option value="-2" <?php if($score == -2) echo "selected";?>>Disappointed</option>

</select> </td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<?php }//end while ($r_cat = mysql_fetch_assoc($result)) ?>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Post" id="Post" value="Post" /></td>
<td><input type="submit" name="Cancel" id="Cancel" value="Cancel" /></td>
</tr>
</form>
</table>


</body>
</html>
----------------------
i know it has errors.. whaaaaaaaaaaa im just new in php.. hehe still need help...

Last edited by stubbykiller; 01-19-2009 at 11:50 AM..
stubbykiller is offline
Reply With Quote
View Public Profile
 
Old 02-02-2009, 03:50 PM Re: creating a survey form
Junior Talker

Posts: 1
Name: viljam
Trades: 0
look at http://www.makesurvey.net and you will not have any problems with it!
judorooni is offline
Reply With Quote
View Public Profile
 
Old 02-03-2009, 11:07 AM Re: creating a survey form
spyderwebtech's Avatar
Skilled Talker

Posts: 51
Trades: 0
Quote:
Originally Posted by judorooni View Post
look at http://www.makesurvey.net and you will not have any problems with it!
I agree with Judorooni.... you can save yourself a lot of time using a free form builder.

I have just started using GOOGLE Documents-->Forms to do exactly what you are doing here. Everything is setup and it tracks the results for you in a spreadsheet.

Open Source it... You would have been done already.
spyderwebtech is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to creating a survey form
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23074 seconds with 12 queries