title: Order by date and chose a category you want to view in php
body: <p>this code let's me view al the problems that are reported and they are order by date ( the oldest on top). I need to insert something to let me view the problems within each Category. The category's are identified with Categorie_ID. Any help?</p>
  
  <pre><code>    &lt;?php
  $db=mysql_connect("localhost","username","password") or die("Kan niet verbinden: ".mysql_error());
  mysql_select_db(,$db);
  
  $sql = "SELECT * FROM Probleem ORDER BY Datum ASC";
  $resultaat  = mysql_query($sql); // voer SQL code uit
  
  echo "&lt;table border=1&gt;";
  echo "&lt;tr&gt;&lt;td&gt;&lt;b&gt;Categorie&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Datum&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Omschrijving;&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Gebruiker_ID&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;"; // bovenste regel
  if ($resultaat) {
      while ($rij = mysql_fetch_array($resultaat)) {
  
      echo "&lt;tr&gt;";
      echo "&lt;td&gt;".$rij["Categorie_ID"]."&lt;/td&gt;";
      echo "&lt;td&gt;".$rij["Datum"]."&lt;/td&gt;";
      echo "&lt;td&gt;".$rij["Probleem"]."&lt;/td&gt;";
      echo "&lt;td&gt;".$rij["Gebruiker_ID"]."&lt;/td&gt;";
      echo "&lt;/tr&gt;";
      }
  }
  echo "&lt;/table&gt;";
  mysql_close($db);
  ?&gt;
  </code></pre>
  
  <p>You can select the category with this code.</p>
  
  <pre><code>&lt;form method="post" action="&lt;?php echo $_SERVER["../h5/PHP_SELF"] ?&gt;"&gt;
  `Selecteer een categorie:&lt;select name="categorieid"&gt;
  &lt;?php
  $db=mysql_connect(("localhost","username","password") or die("Kan niet verbinden: ".mysql_error());
  mysql_select_db(",$db);
  
      $sql = "SELECT * FROM Categorie";
  
      $resultaat  = mysql_query($sql); // voer SQL code uit
      while ($rij = mysql_fetch_array($resultaat)) {
          echo "&lt;option value=\"";
          echo $rij["Categorie_ID"]."\"&gt;";
          echo $rij["Categorienaam"]."&lt;/option&gt;\n";
      }
  
  mysql_close($db);
  ?
  </code></pre>
  
  <blockquote>
    <p>`</p>
  </blockquote>
  
  <p>Tried it with this code , it didn't worked , it did nothing(only showed the categories)</p>
  
  <pre><code>&lt;form method="post" action="&lt;?php echo $_SERVER["../h5/PHP_SELF"] ?&gt;"&gt;
  Selecteer een categorie:&lt;select name="categorieid"&gt;
  &lt;?php
  $db=mysql_connect("localhost","username","password" or die("Kan niet verbinden: ".mysql_error());
  mysql_select_db("",$db);
  
      $sql = "SELECT * FROM Categorie";
  
      $resultaat  = mysql_query($sql); // voer SQL code uit
      while ($rij = mysql_fetch_array($resultaat)) {
          echo "&lt;option value=\"";
          echo $rij["Categorie_ID"]."\"&gt;";
          echo $rij["Categorienaam"]."&lt;/option&gt;\n";
      }
  
  mysql_close($db);
  
  ?&gt;
  
  &lt;?php
  if ($_POST["knop"]) {
  $db=mysql_connect(("localhost","username","password") or die("Kan niet verbinden: ".mysql_error());
  mysql_select_db("",$db);
  
  $sql = "SELECT * FROM Probleem";
  if(isset($_POST["categorieid"])){
      $cat_id = $_POST["categorieid"];
      //sanitize $cat_id to reduce injection risk here
      $sql .= " WHERE `categorieid_id` = $cat_id"; //use correct column name
  }
  $sql .= " ORDER BY Datum ASC";
  $resultaat  = mysql_query($sql); // voer SQL code uit
  
  echo "&lt;table border=1&gt;";
  echo "&lt;tr&gt;&lt;td&gt;&lt;b&gt;Probleem_ID&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Categorie&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Datum&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Omschrijving;&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Gebruiker_ID&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;"; // bovenste regel
  if ($resultaat) {
      while ($rij = mysql_fetch_array($resultaat)) {
  
      echo "&lt;tr&gt;";
  echo "&lt;td&gt;".$rij['Probleem_ID']."&lt;/td&gt;";
  echo "&lt;td&gt;".$rij['Categorie_ID']."&lt;/td&gt;";
  echo "&lt;td&gt;".$rij['Datum']."&lt;/td&gt;";
  echo "&lt;td&gt;".$rij['Probleem']."&lt;/td&gt;";
  echo "&lt;td&gt;".$rij['Gebruiker_ID']."&lt;/td&gt;";
  echo "&lt;/tr&gt;";
      }
  }
  echo "&lt;/table&gt;";
  mysql_close($db);
  }
  ?&gt;
  &lt;form name="form1" method="post" action=""&gt;
    &lt;input type="submit" name="Zoek" id="Zoek" value="zoek"&gt;
  &lt;/form&gt;
  </code></pre>