Log in

View Full Version : Dynamic php page - option selected



KevinBeyers
11-10-2011, 10:53 AM
Hi,

I wanted to make a dynamic php page. I want the user to choose an option you could select in an option box (html) and after that I wish that down the page some text would change. If I take option 1 -> text 1, option 2 -> text 2, ...
But this doesn't work, do I need a button or something to made my code running, and how do I have to use it on the same page?
Or is it possible to run it automaticly after a new choice?

Thanx, Kevin



My code:


<?php
/*
Template Name: template voor Ieder1Trainer #
*/
get_header();

$Tacktiek = "";

$Tacktiek1 = "3-5-2";
$Tacktiek2 = "3-4-3";
$Tacktiek3 = "4-5-1";
$Tacktiek4 = "4-4-2";
$Tacktiek5 = "4-3-3";
$Tacktiek6 = "5-4-1";
$Tacktiek7 = "5-3-2";

$aantalDef;
$aantalMid;
$aantalAtt;

?>

<div id="newsfeed">

<div class="banderol">
<div class="banderol_left"></div>
<h1>Dynamic page</h1>
</div>

<?php if(is_user_logged_in()) {
get_currentuserinfo();
//echo 'Username: ' . $current_user->user_login . "\n";
//echo 'User email: ' . $current_user->user_email . "\n";
?>

<!--
Here you choose a tactiek; 1,2,3, .. after that has been choosen I whise the next php-code would be run (the if-then-elseif-...)
-->

<tr>
<td><p class="formulier">Kies je Tacktiek:</p></td>
<td>
<select size="1" name="$Tacktiek">
<option selected><?php echo $Tacktiek1;?></option>
<option><?php echo $Tacktiek2;?></option>
<option><?php echo $Tacktiek3;?></option>
<option><?php echo $Tacktiek4;?></option>
<option><?php echo $Tacktiek5;?></option>
<option><?php echo $Tacktiek6;?></option>
<option><?php echo $Tacktiek7;?></option>
</select>
</td>
</tr>

<!--
This must be run after choosen a tactiek.
-->

<?php
if($Tacktiek == '3-5-2') {
$aantalDef = 3;
$aantalMid = 5;
$aantalAtt = 2;
} elseif($Tacktiek == '3-4-3') {
$aantalDef = 3;
$aantalMid = 4;
$aantalAtt = 3;
} elseif($Tacktiek == '4-5-1') {
$aantalDef = 4;
$aantalMid = 5;
$aantalAtt = 1;
} elseif($Tacktiek == '4-4-2') {
$aantalDef = 4;
$aantalMid = 4;
$aantalAtt = 2;
} elseif($Tacktiek == '4-3-3') {
$aantalDef = 4;
$aantalMid = 3;
$aantalAtt = 3;
} elseif($Tacktiek == '5-4-1') {
$aantalDef = 5;
$aantalMid = 4;
$aantalAtt = 1;
} elseif($Tacktiek == '5-3-2') {
$aantalDef = 5;
$aantalMid = 3;
$aantalAtt = 2;
}

?>

<!--
After this run, the next code must be run and made a choose of text
-->

<tr>
<td><p class="formulier">
<?php if($aantalDef == '3') {
echo "3 defs"; //Choosen text if aantalDef == 3
}
elseif($aantalDef == '4') {
echo "4 defs"; //Choosen text if aantalDef == 4
}
elseif($aantalDef == '5') {
echo "5 defs"; //Choosen text if aantalDef == 5
}
?>
</p></td>

<!--
Other choose of options, but always the same options.
-->
<td>
<select size="1" name="$Speler4">
<option selected><?php echo $NaamDef1;?></option>
<option><?php echo $NaamDef2;?></option>
<option><?php echo $NaamDefMid1;?></option>
<option><?php echo $NaamDefMid2;?></option>
<option><?php echo $NaamDefMid3;?></option>
<option><?php echo $NaamDefMid4;?></option>
<option><?php echo $NaamDefMid5;?></option>
<option><?php echo $NaamDefMid6;?></option>
<option><?php echo $NaamDefMid7;?></option>
<option><?php echo $NaamDefMid8;?></option>
<option><?php echo $NaamDefMidAtt1;?></option>
<option><?php echo $NaamDefMidAtt2;?></option>
<option><?php echo $NaamDefMidAtt3;?></option>
</select>
</td>
</tr>


<?php
}
else{
echo 'U dient in te loggen.';
}
?>


</div>

<?php get_footer(); ?>