By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,700 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,700 IT Pros & Developers. It's quick & easy.

How to calculate mark using check box

P: 1
hello n gud day every one

basically my project is about personality test, it content 6 page of question which each page has 13 question

page 1

question 1 checkbox1
question 2 checkbox2
question 13 checkbox13

once user click on next page, system will calculate number of checked check box and display the value on result page

and i having a problem to calculate number of checked checkbox in php.

i hope u guys can help me~

below is some of my code to retrieve data from dtbase

Expand|Select|Wrap|Line Numbers
  1.   <?php mysql_select_db("esci", $conn);
  2.         $result = mysql_query("SELECT * FROM personality_rule WHERE conclusion = 'Realistic'");    
  3.     while($data = mysql_fetch_array($result))
  4.       {
  5.     $rules = str_replace("_"," ",$data['question']);
  6.       echo'
  7.      <tr>
  8.      <td>'. $rules.'</td>
  9.      <td align="center"><input type="checkbox" name="ans"/></td>
  10.      </tr>
  11.      ';
  12.      }
  13.      ?>
Apr 6 '10 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 1,584
since question - answer are pairs, you need something to tie those two together.

I can't get much from what you said or your code, but let's say you have a questions table. each question has an ID, and also a column perhaps if the question has finite set of answers. (i.e. A= Agree, B =Disagree, C = Don't care, etc)

You should store your answers in a another table that has that question ID and the value of the answer, be it an option, free text or a boolean Yes/No.

Your html input tag's name should somehow tie the answer to the question it answers.

for example:

Expand|Select|Wrap|Line Numbers
  1. <input type="radio" name="questionID_1" value=""/>
  3. // or 
  5. <input type="text" name="questionID_442" value="" /> 
Store the answer values in the session or in a table after each page, it's up to you.

Apr 6 '10 #2

P: 96
@ dlite922

that is a good idea i never thought of doing it that simple...

Apr 9 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.