juniorek9 Posted December 11, 2010 Share Posted December 11, 2010 i would like to change the code so there is two optional answers "yes" and "no" to each question. how can i do that? any suggestions? thanks [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/221321-table-in-php/ Share on other sites More sharing options...
MMDE Posted December 11, 2010 Share Posted December 11, 2010 You've been asking about this for some days, so I just spent some minutes writing it for you. <?php echo '<h1>Are You a superhero?</h1> <form method="post" action="">'; $questions[]='Would You like to fly?'; $questions[]='Do You like helping people?'; $questions[]='Do You like to work on your own?'; $questions[]='Do wou look good in tight outfit?'; $questions[]='Do you have strong personality?'; $questions[]='Do you drive?'; $questions[]='Do you like to travel?'; for($i=0;$i<count($questions);$i++){ echo '<br /> '.$questions[$i].'<br /> <input type="radio" name="question'.$i.'" value="yes" />yes<br /> <input type="radio" name="question'.$i.'" value="no" />no'; } echo '<br /> <input type="submit" value="go"> </form>'; if(!empty($_POST['question0'])){ $totalpoints=0; for($i=0;$i<count($questions);$i++){ if(!empty($_POST['question'.$i])){ if($_POST['question'.$i]=='yes'){ $totalpoints++; } } } echo '<br /> '; if($totalpoints==count($questions)){ echo 'You are a superhero for sure!!'; }elseif($totalpoints>count($questions)/2){ echo 'You are probably a superhero!'; }elseif($totalpoints>count($questions)/4){ echo 'You might be a superhero!'; }elseif($totalpoints<count($questions)/4 && $totalpoints!=0){ echo 'You are most likely not a superhero!'; }else{ echo 'You are not a superhero!'; } } ?> Hope you can try to read and understand what I've done, mess around with it a bit. You don't learn by others doing it for you. You must test and mess around with it till you've understood perfectly well how it works. Quote Link to comment https://forums.phpfreaks.com/topic/221321-table-in-php/#findComment-1145761 Share on other sites More sharing options...
ADynaMic Posted December 11, 2010 Share Posted December 11, 2010 Hey... I'm still not a PHP genius. But I tried your problem and came out with an simple answer to do what you wanted. Try it, Let us know if these answers from MMDE and me solved your problem..... <html> <body> <h1>Are You a superhero?</h1> <?php // This will print the posted array.. You can see what you get if(isset($_POST['go'])){ print_r($_POST['yesno']); } ?> <form name="myForm" method="post"> <?php $transport = array('r' => 'would You like to fly?', 'a' => 'do You like helping people?', 'p' => 'do You like to work on your own?', 'h' => 'do wou look good in tight outfit?', 'c' => 'do you have strong personality?', 's' => 'do you drive?', 'f' => 'do you like to travel?'); foreach ($transport as $key => $transport) { //echo "<input type='radio' name='transport' value='$key'/> $transport <br/>" ; //This is the line I changed.... //Each button group [yes/no] has it's own array key equal to your Transport array key // - ADynaMic echo "$transport : <input type ='radio' name='yesno[$key]' value = '1'>YES</input> <input type ='radio' name='yesno[$key]' value = '0'>NO</input></br>"; } ?> <input type="submit" value="go" name="go"> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/221321-table-in-php/#findComment-1145784 Share on other sites More sharing options...
juniorek9 Posted December 11, 2010 Author Share Posted December 11, 2010 Thanks a Lot guys. You are absolute stars. now that i see how it works and what id does i can expand it a bit further. i wouldn`t be able to do so without your help though so i really appreciate it. i wish someone could explain it to me before. do you know any good books that would help me to sort my lack of knowledge?? thanks again Just made my day!! Quote Link to comment https://forums.phpfreaks.com/topic/221321-table-in-php/#findComment-1145830 Share on other sites More sharing options...
desjardins2010 Posted December 11, 2010 Share Posted December 11, 2010 youtube - phpacademy helped me alot Quote Link to comment https://forums.phpfreaks.com/topic/221321-table-in-php/#findComment-1145853 Share on other sites More sharing options...
ADynaMic Posted December 12, 2010 Share Posted December 12, 2010 Dear juniorek9, I'm really happy.. Even if I had a little programming experience, Its only 3 weeks (to this coming Wednesday) I started reading PHP. You wanna know what helped me? This is a superb tutorial, Read it, It will polish you up with most of the things you ever want.. http://devzone.zend.com/article/627 The next is the php online manual, I believe you already use it everyday.... http://php.net/manual/en/index.php Keep it up... Regards, ADynaMic Quote Link to comment https://forums.phpfreaks.com/topic/221321-table-in-php/#findComment-1146069 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.