G
G
gattsteroff2020-05-01 08:32:41
PHP
gattsteroff, 2020-05-01 08:32:41

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;
  }}}}
  ?>

Where it turns out that by selecting and clicking on the "Show" button, certain blocks are displayed below, depending on the selected name, where 0 is "Select the tariff you need .." and when you select it, nothing is shown and where subsequent names have their own number .
It is written below that if "Post" has a value of 1, then one is displayed, otherwise the subsequent calculations take place.
But all this did not work as I thought, and instead of displaying the selected one, it always displayed the very first stage.
Then I tried to replace the previous calculation with this code:
<? 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;}?>

After that, I received the output of absolutely all blocks.
How can this be fixed and where is the fatal error here or how is it better

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PQR, 2020-05-06
@PQR

You are comparing a superglobal variable $_POSTwith 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 question

Ask a Question

731 491 924 answers to any question