Hiddem PlayZ
Hiddem PlayZ

Reputation: 21

<option> is having each option its own dropdown

I tried putting the loop inside but then when I pick a category it won't print in the echo and if the loop is outside like right now each category is printed alone I want them all in one tab and one go button

<?php
while($row = mysqli_fetch_array($result)) {
    $category = $row["category"];
    ?>

    <form action="" method="post">
        <select name="work_place">
            <option value="<?php echo $category;?>"><?php echo $category;?></option>
        </select>
        <input type="submit" value="go" />
    </form>
<?php
}
<?php
    $post = (isset($_POST['work_place'])) ? $_POST['work_place'] : '';
    echo $post;
?>

Image of current issue:

image of current issue

Upvotes: 2

Views: 50

Answers (1)

Greg Kelesidis
Greg Kelesidis

Reputation: 1054

<form action="" method="post">
  <select name="work_place">
  <?php
  while($row = mysqli_fetch_array($result)) {
    $category = $row["category"];
  ?>
      <option value="<?php echo $category;?>"><?php echo $category;?>
      </option>
<?php
  } ?>
  </select>
  <input type="submit" value="go" />
</form>  

You want to loop over 'option', only.
You do not want multiple forms and 'select' inputs.

Upvotes: 2

Related Questions