gum1982 Posted November 4, 2009 Share Posted November 4, 2009 Hi im new to php so sorry about my code i know its wrong that's why i need some help im making a survey form that needs to analysis the percentage from a set off questions hear is my code it works fine but as i add more questions it justs get bigger and bigger. this is just snippet of one group and their is about 20. Im trying to get my head around arrays at the moment would this be the right way? <?php if (is_array($_POST) && count($_POST) > 1) { $exercise_value = $_POST['q1']; $exercise_value1 = $_POST['q2']; $exercise_value2 = $_POST['q3']; $exercise_value3 = $_POST['q4']; } ?> <FORM METHOD="post" ACTION=""> <table width="805" height="789"> <tr><h2>Marketing</h2></tr> <!----- SECTION -----> <tr> <td width="688">I know where I want .....</td> <td width="96"> <input type="radio" name="q1" value="1"> <input type="radio" name="q1" value="2"> <input type="radio" name="q1" value="3"> <input type="radio" name="q1" value="4"> </td> </tr> <tr> <td width="688">I have a written marketing....</td> <td width="96"> <input type="radio" name="q2" value="1"> <input type="radio" name="q2" value="2"> <input type="radio" name="q2" value="3"> <input type="radio" name="q2" value="4"> </td> </tr> <tr> <td width="688">I understand the .....</td> <td width="96"> <input type="radio" name="q3" value="1"> <input type="radio" name="q3" value="2"> <input type="radio" name="q3" value="3"> <input type="radio" name="q3" value="4"> </td> </tr> <tr> <td width="688" height="22">Our current prices</td> <td width="96"> <input type="radio" name="q4" value="1"> <input type="radio" name="q4" value="2"> <input type="radio" name="q4" value="3"> <input type="radio" name="q4" value="4"> </td> </tr> <tr> <td width="688" height="20">Percentage for this section.</td> <td width="96"><?php echo $exercise_value*100/16+$exercise_value1*100/16+$exercise_value2*100/16+$exercise_value3*100/16 . "%"; ?></td> </tr> <!----- SECTION END -----> Link to comment https://forums.phpfreaks.com/topic/180265-help-with-arrays/ Share on other sites More sharing options...
seanlim Posted November 4, 2009 Share Posted November 4, 2009 I guess something like this would do? $questions = 16; $sum = 0; for($i=1;$i<=$questions;$i++) $sum += $_POST['q'.$i]; .... echo ($sum*100/$questions)."%"; Link to comment https://forums.phpfreaks.com/topic/180265-help-with-arrays/#findComment-950937 Share on other sites More sharing options...
gum1982 Posted November 4, 2009 Author Share Posted November 4, 2009 brilliant thanks ill give that a try Link to comment https://forums.phpfreaks.com/topic/180265-help-with-arrays/#findComment-950940 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.