title: Notice: Undefined variable: table in C:\XAMPP\htdocs\progscores.php on line 27
body: <p>I have a form with drop down menus. Whenever I select a program, the system displays the program scores table. But when I select a service name it doesn't display the service table. Plus, is there any better,faster and efficient way to display the tables from database?</p>
  
  <p>This is my form:</p>
  
  <p><img src="https://i.stack.imgur.com/OqHNZ.png" alt="form"></p>
  
  <p>The errors I get:</p>
  
  <p><img src="https://i.stack.imgur.com/TifMK.png" alt="errors"></p>
  
  <p>progscores.php</p>
  
  <pre><code>  &lt;?php
  
      include'connect.php';
  
      $crit=@$_POST['crit'];
      $y2005=@$_POST['y2005'];
      $y2006=@$_POST['y2006'];
      $y2007=@$_POST['y2007'];
      $y2008=@$_POST['y2008'];
      $y2009=@$_POST['y2009'];
      $y2010=@$_POST['y2010'];
  
      switch($_POST['program'])
      {
            case 'Computer Science':
               $table = 'csprog';
               break;
            case 'BAED':
              $table = 'baedprog';
               break;
            case 'Psychology':
               $table = 'psyprog';
               break;
  
        }
  
       $res = mysql_query("SELECT * FROM {$table}");
  
   ?&gt; 
  
    &lt;html&gt;
    &lt;body&gt;
    &lt;table width="600" border="1" cellspacing="1"&gt;
      &lt;tr&gt;
           &lt;th&gt;Criteria&lt;/th&gt;
           &lt;th&gt;2005&lt;/th&gt;
           &lt;th&gt;2006&lt;/th&gt;
           &lt;th&gt;2007&lt;/th&gt;
           &lt;th&gt;2008&lt;/th&gt;
           &lt;th&gt;2009&lt;/th&gt;
           &lt;th&gt;2010&lt;/th&gt;
     &lt;/tr&gt;
  
      &lt;?php
         while($table=mysql_fetch_assoc($res)){
  
           echo "&lt;tr&gt;";
  
           echo "&lt;td&gt;".$table['crit']."&lt;/td&gt;";
  
           echo "&lt;td&gt;".$table['y2005']."&lt;/td&gt;";
  
           echo "&lt;td&gt;".$table['y2006']."&lt;/td&gt;";
  
           echo "&lt;td&gt;".$table['y2007']."&lt;/td&gt;";
  
           echo "&lt;td&gt;".$table['y2008']."&lt;/td&gt;";
  
           echo "&lt;td&gt;".$table['y2009']."&lt;/td&gt;";
  
           echo "&lt;td&gt;".$table['y2010']."&lt;/td&gt;";
  
           echo "&lt;/tr&gt;";
  
        }
     ?&gt;
    &lt;/table&gt;
    &lt;/body&gt;
    &lt;/html&gt;
  
  
    principal.php
  
        &lt;?php
  
            include 'connect.php';
  
            if($_POST['program']){
               include 'progscores.php';
  
            }elseif($_POST['services']){
               include 'servscores.php';
            }
  
          ?&gt; 
  
  
     servscores.php
  
  
           &lt;?php
  
              include'connect.php';
  
              $scrit=@$_POST['scrit'];
              $sy2005=@$_POST['sy2005'];
              $sy2006=@$_POST['sy2006'];
              $sy2007=@$_POST['sy2007'];
              $sy2008=@$_POST['sy2008'];
              $sy2009=@$_POST['sy2009'];
              $sy2010=@$_POST['sy2010'];
  
              switch($_POST['services'])
              {
                  case 'Library':
                     $stable = 'library';
                     break;
                  case 'Course Administrator':
                     $stable = 'cadmin';
                     break;
                 case 'Front Desk':
                     $stable = 'frontdesk';
                     break;
                 case 'Clubs and Societies':
                     $stable = 'clubs';
                     break;
                case 'IT Services and Facilities':
                     $stable = 'itservice';
                     break;
                case 'International Student Office':
                    $stable = 'stoffice';
                     break;
            }
  
            $res2 = mysql_query("SELECT * FROM {$stable}");
  
         ?&gt; 
  
           &lt;html&gt;
           &lt;body&gt;
              &lt;table width="600" border="1" cellspacing="1"&gt;
                &lt;tr&gt;
                     &lt;th&gt;Criteria&lt;/th&gt;
                     &lt;th&gt;2005&lt;/th&gt;
                     &lt;th&gt;2006&lt;/th&gt;
                     &lt;th&gt;2007&lt;/th&gt;
                     &lt;th&gt;2008&lt;/th&gt;
                     &lt;th&gt;2009&lt;/th&gt;
                     &lt;th&gt;2010&lt;/th&gt;
                &lt;/tr&gt;
  
          &lt;?php
               while($stable=mysql_fetch_assoc($res2)){
  
                echo "&lt;tr&gt;";
  
                echo "&lt;td&gt;".$stable['scrit']."&lt;/td&gt;";
  
                echo "&lt;td&gt;".$stable['sy2005']."&lt;/td&gt;";
  
                echo "&lt;td&gt;".$stable['sy2006']."&lt;/td&gt;";
  
                echo "&lt;td&gt;".$stable['sy2007']."&lt;/td&gt;";
  
                echo "&lt;td&gt;".$stable['sy2008']."&lt;/td&gt;";
  
                echo "&lt;td&gt;".$stable['sy2009']."&lt;/td&gt;";
  
                echo "&lt;td&gt;".$stable['sy2010']."&lt;/td&gt;";
  
               echo "&lt;/tr&gt;";
  
           }
         ?&gt;
  
         &lt;/table&gt;
         &lt;/body&gt;
         &lt;/html&gt;
  </code></pre>