-1

I'm trying to include a dropdown menu (dynamic and fueled by a Database) into a switch but can't figure out how.. Anyone already tried/done something similar?

<?php
$favcolor = "red";

switch ($favcolor) {
    case "red":
        echo "Your favorite color is red!";
        echo "<select>
            $query = mysqli_query($conn, "SELECT Spessore FROM spessori");
            while($row = mysqli_fetch_assoc($query)){
                <option>echo $row['Spessore'];</option>
                }
              </select>
        break;
         case "blue":
        echo "Your favorite color is blue!";
        break;
    case "green":
        echo "Your favorite color is green!";
        break;
    default:
        echo "Your favorite color is neither red, blue, nor green!";
    }
?>
Maso
  • 1
  • 2

1 Answers1

0

You've used echo in wrong way. Use it as:

    echo "<select>";
        $query = mysqli_query($conn, "SELECT Spessore FROM spessori");
        while($row = mysqli_fetch_assoc($query)){
            echo "<option>". $row['Spessore'] ."</option>";
             }
    echo "</select>";

You should to understand, that HTML tags don't work in PHP.

Aksen P
  • 4,564
  • 3
  • 14
  • 27