title: Dynamically creating cases for a php switch statement
body: <p>I am writing a switch statement in php which will determine what a mysql query will be based on posted data.  The amount data that is posted varies based on the database, which creates the form.  Is there any way that I can have the possible cases pull from the database because the same code is executed for all of them with some case specific modifications. The reason I don't just use one possibility instead of the switch is because there are other non database related cases that can feed into the switch.  </p>
  
  <p>This may clear things up</p>
  
  <p>I have 2 pages people.php and edit.php.  people.php dynamically creates a table of members in a building based on the building Id which is sent via get.  From this table a user can select what they would like to change about the records from a drop down menu and then the script posts everything to edit.php.  If a user wishes to change someone's building then the switch case catches thais and creates a form to ask which building they will be changed to. This then posts back to edit.php.  Do I have to hard code each building into the switch or can I make it dynamically create cases based on the available buildings from mysql?</p>
  
  <p><code>echo"&lt;td&gt;&lt;select name='action'&gt;
          &lt;option value='save' selected='yes'&gt;Save Changes&lt;/option&gt;
          &lt;option value='delete'&gt;Delete Record&lt;/option&gt;
          &lt;option value='more'&gt;Add Additional Phone Numbers and or Email Addresses&lt;/option&gt;
          &lt;option value='building'&gt;Change This person's Building&lt;/option&gt;
          &lt;/select&gt;&lt;/td&gt;"</code></p>
  
  <p>this is created in every row of the table of people which will determine what the form will do with the data in edit.php</p>
  
  <pre><code>switch ($_POST['action'])
  {
          case 'save':
                  update($_POST);
                  header("Location: people.php?bid=".$_POST['bid']);
                  break;
          case 'delete': //Havent written delete person code yet
                  break;
          case 'more': //havent written add more phone number or emails yet
                  break;
          case 'building': echo "Move ".$_POST['fname']." ".$_POST['mname']." ".$_POST['lname']." to which building?
                  &lt;br/&gt;&lt;form action='edit.php' method='POST'&gt;&lt;select name='action'&gt;"
                  compile_permissions($_SESSION['uid']);
                  foreach($_SESSION['buildings'] as $value)
                  {
                          $query="select name from schools where bid='$value'";
                          $result=mysql_query($query);
                          $row=mysql_fetch_array($result);
                          echo "&lt;option value='$value'&gt; Move to ".$row['name']."&lt;/option&gt;";
                  }
                  echo "&lt;/select&gt;&lt;br/&gt;&lt;input type='submit' value='Go'&gt;&lt;/form&gt;"
                  break;
          default: header("Location:index.php");
                  break;
  }
  </code></pre>
  
  <p>I Need to pass the pid and the bid to edit.php with this form so I can use a query to update their building how can I go about doing this?</p>