-3

Hello i have one problem. This is example of the code :

I have a multiple select form :

<p>Plant</p><form action="" method="post">
   <select name="select9[]" multiple="multiple"style="height:90px;">
  <option value="CZ10">CZ10</option>
  <option value="CZ20">CZ20</option>
  <option value="GB10">GB10</option>
  <option value="GB11">GB11</option>
  <option value="GB20">GB20</option>
   </select>

and this is my switch case:

 if(isset($_POST['select9'])){
$selectttttt = $_POST['select9'];
$aaaaaa="";
foreach($selectttttt as $option => $bbbbbb)
{
switch ($bbbbbb) {
  case 'CZ10':
        echo 'ZMD_LPLCNMAT_CZ10</br>ZMD_LPQAMAT_CZ10</br>ZMD_LSOCNMAT_CZ10</br>ZMD_PLNTMAT_CZ10</br>ZMD_SLSVMAT_CZ10</br>';
        break;
  case 'CZ20':
        echo 'ZMD_LPLCNMAT_CZ20</br>ZMD_LPQAMAT_CZ20</br>ZMD_LSOCNMAT_CZ20</br>ZMD_PLNTMAT_CZ20</br>ZMD_SLSVMAT_CZ20</br>';
        break;
  case 'GB10':
        echo 'ZMD_LPLCNMAT_GB10</br>ZMD_LPQAMAT_GB10</br>ZMD_LSOCNMAT_GB10</br>ZMD_PLNTMAT_GB10</br>ZMD_SLSVMAT_GB10</br>';
        break;
  case 'GB11':
        echo 'ZMD_LPLCNMAT_GB11</br>ZMD_LPQAMAT_GB11</br>ZMD_LSOCNMAT_GB11</br>ZMD_PLNTMAT_GB11</br>ZMD_SLSVMAT_GB11</br>';
        break;
  case 'GB20':
        echo 'ZMD_LPLCNMAT_GB20</br>ZMD_LPQAMAT_GB20</br>ZMD_LSOCNMAT_GB20</br>ZMD_PLNTMAT_GB20</br>ZMD_SLSVMAT_GB20</br>';
        break;
  case ($bbbbbb == 'GB20' && $bbbbbb=='GB10'):
        echo 'ZMD_LPLCNMAT_GB20</br>ZMD_LPQAMAT_GB20</br>ZMD_LSOCNMAT_GB20</br>ZMD_PLNTMAT_GB20</br>ZMD_SLSVMAT_GB20</br>';
        break;
        }

Code works that if user select for example GB11 the result will be :

PLANT GB11

ZMD_LPLCNMAT_GB11 ZMD_LPQAMAT_GB11 ZMD_LSOCNMAT_GB11 ZMD_PLNTMAT_GB11 ZMD_SLSVMAT_GB11

I wan't to have option when i select GB10 and GB20 that i get result for example "test" and not combination of them.

i tried to do something like this, but the result was not correct :

case ($bbbbbb =='GB20' && $bbbbbb=='GB10'):

        echo 'test';
        break;
        }

result was only for GB10.

Thank you for your help.

  • Check this: https://stackoverflow.com/questions/16706716/using-two-values-for-one-switch-case-statement?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – DsRaj Jun 06 '18 at 05:03
  • Hi, i tried following this link https://stackoverflow.com/questions/16706716/using-two-values-for-one-switch-case-statement?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa but when i use it like that i get result for both cases, if select for example gb11 and gb20 i get result for gb11 and gb20 but i need a single result for combination of fb11 and gb20 that is different from result of gb11 and gb20 – Ante Marić Jun 06 '18 at 08:36
  • check the current answer – DsRaj Jun 06 '18 at 09:28
  • Possible duplicate of [PHP - Switch multiple case statement](https://stackoverflow.com/questions/22074104/php-switch-multiple-case-statement) – Nico Haase Aug 26 '18 at 07:08
  • `$bbbbbb` (using proper variable names will help others and future you to better understand your code cannot be equal to `'GB20'` and `'GB10'` at the same time. A variable can only have a single value – knittl Aug 26 '18 at 10:11

1 Answers1

0

Check for multiple options exits and then you can check the case

$multiple = false;
if(in_array('GB20',$selectttttt) && in_array('GB29',$selectttttt)){
    $multiple = true;
}
foreach($selectttttt as $option => $bbbbbb)
.
.
.
case $multiple == true;
    echo "New Multiple Case";
DsRaj
  • 2,288
  • 1
  • 16
  • 26