gum1982 Posted October 22, 2009 Share Posted October 22, 2009 Can someone please tell me how i would set-up an array to show what is the most chosen answer when this form is submitted. Example: you chose mostly A's you chose mostly B's you chose mostly C's <form class="cmxform" id="form1" method="post" action="process.php"> <fieldset> <h2>How healthy is your business ?</h2> <legend>Is your business growing?</legend> <ul> <li> <label>Yes, our sales have increased over last year.</label> <input type="radio" name="growing" value="1" /> A</li> <li> <label>Our sales have been fairly flat over the last few years.</label> <input type="radio" name="growing" value="2" /> B</li> <li> <label>Unfortunately, sale are declining, but we have a solid customer base.</label> <input type="radio" name="growing" value="3" /> C</li> </ul> <legend>Is your business profitable?</legend> <ul> <li> <label>Our net profit as a percentage is more than I would get from a building society.</label> <input type="radio" name="profitable" value="1" /> A</li> <li> <label>We are just about breaking even this year.</label> <input type="radio" name="profitable" value="2" /> B</li> <li> <label> I’m quite concerned that we are not making enough profit from our sales activity.</label> <input type="radio" name="profitable" value="3" /> C</li> </ul> <legend>How do you win new customers?</legend> <ul> <li> <label>Our products and services are unique – people tell us we are the number-one supplier.</label> <input type="radio" name="customers" value="1" /> A</li> <li> <label>We follow-up every quotation to find out who won the business,</label> <input type="radio" name="customers" value="2" /> B</li> <li> <label>We lost a big customer recently, and I need to work out how to replace those sales</label> <input type="radio" name="customers" value="3" /> C</li> </ul> </fieldset> <p> <input class="submit" type="submit" value="Submit"/> </p> </form> Link to comment https://forums.phpfreaks.com/topic/178581-solved-mostly-choosen-radio-button-results-a-b-c/ Share on other sites More sharing options...
purpleshadez Posted October 22, 2009 Share Posted October 22, 2009 This is a quick and untested answer and I'm sure there's a better way, but something like this should work. <?php // process.php $a = 0; $b = 0; $c - 0; foreach($_POST as $data) { if($data == 1) { $a++; } elseif($data == 2) { $b++; } elseif($data == 3) { $c++; } } if($a > $b && $a > $c) { echo 'you answered mostly A'; } elseif($b > $a && $b > $c) { echo 'you answered mostly B'; } else { echo 'you answered mostly C'; } ?> Link to comment https://forums.phpfreaks.com/topic/178581-solved-mostly-choosen-radio-button-results-a-b-c/#findComment-941814 Share on other sites More sharing options...
gum1982 Posted October 22, 2009 Author Share Posted October 22, 2009 Thanks your a legend worked first time god i wish i was good a php. Link to comment https://forums.phpfreaks.com/topic/178581-solved-mostly-choosen-radio-button-results-a-b-c/#findComment-941820 Share on other sites More sharing options...
purpleshadez Posted October 22, 2009 Share Posted October 22, 2009 Thanks your a legend worked first time god i wish i was good a php. No probs, there is a typo in my code though. $a = 0; $b = 0; $c - 0; where i have a minus sign for $c it should be an equals sign $c = 0; Link to comment https://forums.phpfreaks.com/topic/178581-solved-mostly-choosen-radio-button-results-a-b-c/#findComment-941831 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.