title: How to use a switch case statement in a while loop
body: <p>I have a function where you can press the button shuffle, and then you get three random rows from MySQL database, with the columnnames <code>id, weekday, description</code>. At the moment I just get random rows without any conditions. Therefore I made a select form, where I can choose to only get printed records, when weekday is equal to wednesday.  </p>
  
  <p>I tried to make a switch case statement, but I am really not sure how I have to set that in my while loop?</p>
  
  <p><a href="https://i.stack.imgur.com/uYF7Y.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uYF7Y.jpg" alt="Shuffle"></a></p>
  
  <p><strong>index.php</strong></p>
  
  <pre><code>&lt;select name="weekday" class="form-control selectpicker" &gt;
          &lt;option value=" "&gt;Select Weekday&lt;/option&gt;
          &lt;option value="alldays"&gt;All Days&lt;/option&gt;
          &lt;option value="wednesday"&gt;Wednesday&lt;/option&gt;
          &lt;option value="saturday"&gt;Saturday&lt;/option&gt;
  &lt;/select&gt;
  &lt;div&gt;
      &lt;form method="post"&gt;
          &lt;button class="btn btn-warning"&gt;Shuffle&lt;/button&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  &lt;div&gt;
      &lt;h4&gt;Shuffle Result&lt;/h4&gt;&lt;hr&gt;
      &lt;?php include 'shuffle.php' ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>shuffle.php</strong></p>
  
  <pre><code>&lt;?php
      $sql = "SELECT id, description FROM articles ORDER BY RAND ( ) LIMIT 3";
      $res = $mysqli-&gt;query($sql);
  
      //print($res);
      if ($res-&gt;num_rows &gt; 0) {
      // output data of each row
          while($row = $res-&gt;fetch_assoc()) {
              echo "Number: " . $row["id"]. "&lt;br&gt;" .
                   "Description: " . $row["description"]. "&lt;br&gt;&lt;br&gt;".
                   '&lt;div class="btn btn-warning btn-open-modal" data-id="'.$row["id"].'"&gt;See Details '.'&lt;/div&gt;&lt;br&gt;&lt;br&gt;';              
          }
      } else {
      echo "0 results";
      }
  </code></pre>
  
  <p>I tried to make a switch case code for my while loop:</p>
  
  <pre><code>switch($_POST['weekday']){
            case 'alldays':
                echo "Alldays";
            break;
            case 'wednesday':
                echo "Wednesday";
            break;
            case 'saturday':
                echo "Saturday";
            break;
            default:
                echo "Something went wrong";
      }
  </code></pre>