Jump to content

table in php


juniorek9

Recommended Posts

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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!!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.