Answer the question
In order to leave comments, you need to log in
How can I display a separate block depending on the selected name in the drop-down list?
There is a page where there is, let's say there are 4 names in the "select" to choose from. Depending on the selected name, a specific block should be displayed.
Wrote the following code:
<?php
$elegant = file_get_contents('./tarifs/elegant.php');
$myRules = file_get_contents('./tarifs/myRules.php');
$noDamage = file_get_contents('./tarifs/noDamage.php');
$canAll = file_get_contents('./tarifs/canAll.php');
$none = file_get_contents('./tarifs/none.php');
$values=array("Выберите нужный вам тариф..","Элегантный","Несокрушимый","Можно все", "Свои правила");
$number=count($values);
?>
<form method="post">
<select name="polling" class="hover">
<? for($i=0; $i<$number; $i++) echo "<option value=\"$i\"> $values[$i]</option>"; ?></select><br><br>
<li><input type="submit" value="Показать" class="hover"/></li>
</form>
<? if($_POST=1){
echo $elegant;
}else{
if ($_POST=2){
echo $noDamage;
}else{
}if ($_POST=3){
echo $canAll;
}else{if ($_POST=4){
echo $myRules;
}else{if ($_POST=0){
echo $nones;
}}}}
?>
<? if($_POST=1){
echo $elegant;}?>
<? if ($_POST=2){
echo $noDamage;}?>
<? if ($_POST=3){
echo $canAll;}?>
<? if ($_POST=4){
echo $myRules;}?>
<? if ($_POST=0){
echo $none;}?>
Answer the question
In order to leave comments, you need to log in
You are comparing a superglobal variable $_POST
with a number: , there are several errors:
1) the comparison is done using a double equals sign
2) comparison with a number does not make sense, because is an array, not a number.
It is necessary to compare like this:
3) Brackets are not correctly placed through if / else constructions, all the logic is broken there (although purely by chance everything turned out to be syntactically correct) if($_POST=1)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question