title: Generating a case switch for every row in db
body: <p>I'm generating a case for a switch in js for every row not empty in my db. For every case I'm generating a new option: </p>
  
  <pre><code>&lt;script language="javascript" type="text/javascript"&gt;
  function dropdownlist(listindex)
  {
      document.formname.subcategory.options.length = 0;
  
      switch (listindex)
      {
          &lt;?php $stmt = $conn-&gt;query("SELECT * FROM `filters` WHERE `primary_category` &lt;&gt; '' "); ?&gt; 
          &lt;?php while ($row = $stmt-&gt;fetch()) { ?&gt;
            case "&lt;?php echo $row['primary_category']; ?&gt;" :
                  &lt;?php $stmt2 = $conn-&gt;query("SELECT * FROM `filters` WHERE `second_category` &lt;&gt; '' "); ?&gt;
                  &lt;?php $i= 0; ?&gt;
                  &lt;?php while ($row2 = $stmt2-&gt;fetch()) { ?&gt;
                      &lt;?php if($i === count($row2)) { ?&gt;
  
                         break;
  
                      &lt;?php } else { ?&gt;
                          document.formname.subcategory.options[&lt;?php echo $i;?&gt;]=new Option("&lt;?php echo $row2['second_category']; ?&gt;","value1.1")
                          &lt;?php $i++; ?&gt;
                      &lt;?php } ?&gt;
  
  
  
                  &lt;?php }?&gt;
              &lt;?php  }?&gt;
  
            default:
                document.formname.subcategory.options[0]=new Option("Select Category")
                break;
        }
        return true;
        }
  &lt;/script&gt;
  </code></pre>
  
  <p>For some reason, one second category is not shown , maybe the break happens to quickly. This is how it looks:</p>
  
  <p><a href="https://i.stack.imgur.com/MrHGK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MrHGK.png" alt="enter image description here"></a></p>
  
  <p>Inside my db there is one more :
  <a href="https://i.stack.imgur.com/mLKx7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mLKx7.png" alt="enter image description here"></a></p>
  
  <p>What am I doing wrong?</p>
  
  <p>Edit: The whole purpuse is to give the user the option to choose for every category a sub cutegory. </p>
  
  <p>The html for those Category and Sub-Category is here :</p>
  
  <pre><code>&lt;table width="50%" border="0" cellspacing="0" cellpadding="5"&gt;
      &lt;tr&gt;
          &lt;td&gt;Category:&lt;/td&gt;
          &lt;td width="59%" align="left" valign="middle"&gt;&lt;select name="category" id="category" onchange="dropdownlist(this.options[this.selectedIndex].value);"&gt;
  
          &lt;option class="hidden"  selected disabled value=""&gt;Select Category&lt;/option&gt;
          &lt;!-- Generate categories --&gt;
  
          &lt;?php $stmt = $conn-&gt;query("SELECT * FROM `filters` WHERE `primary_category` &lt;&gt; '' "); ?&gt;
            &lt;?php while ($row = $stmt-&gt;fetch()) { ?&gt;
              &lt;option class = "form-control" name ="primary_category"&gt;&lt;?php echo $row['primary_category']; ?&gt;&lt;/option&gt;
          &lt;?php } ?&gt;
  
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td &gt;Sub Category:&lt;/td&gt;
          &lt;td align="left" valign="middle"&gt;&lt;script type="text/javascript" language="JavaScript"&gt;
          document.write('&lt;select name="subcategory"&gt;&lt;option value=""&gt;Select Sub-Category&lt;/option&gt;&lt;/select&gt;')
          &lt;/script&gt;
          &lt;noscript&gt;&lt;select name="subcategory" id="subcategory" &gt;
          &lt;option class ="hiden" selected disabled value=""&gt;Select Sub-Category&lt;/option&gt;
          &lt;/select&gt;
          &lt;/noscript&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;/table&gt;
  </code></pre>