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?
<?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 "<table border=1>";
echo "<tr><td><b>Categorie</b></td><td><b>Datum</b></td><td><b>Omschrijving;</b></td><td><b>Gebruiker_ID</b></td></tr>"; // bovenste regel
if ($resultaat) {
while ($rij = mysql_fetch_array($resultaat)) {
echo "<tr>";
echo "<td>".$rij["Categorie_ID"]."</td>";
echo "<td>".$rij["Datum"]."</td>";
echo "<td>".$rij["Probleem"]."</td>";
echo "<td>".$rij["Gebruiker_ID"]."</td>";
echo "</tr>";
}
}
echo "</table>";
mysql_close($db);
?>
You can select the category with this code.
<form method="post" action="<?php echo $_SERVER["../h5/PHP_SELF"] ?>">
`Selecteer een categorie:<select name="categorieid">
<?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 "<option value=\"";
echo $rij["Categorie_ID"]."\">";
echo $rij["Categorienaam"]."</option>\n";
}
mysql_close($db);
?
`
Tried it with this code , it didn’t worked , it did nothing(only showed the categories)
<form method="post" action="<?php echo $_SERVER["../h5/PHP_SELF"] ?>">
Selecteer een categorie:<select name="categorieid">
<?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 "<option value=\"";
echo $rij["Categorie_ID"]."\">";
echo $rij["Categorienaam"]."</option>\n";
}
mysql_close($db);
?>
<?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 "<table border=1>";
echo "<tr><td><b>Probleem_ID</b></td><td><b>Categorie</b></td><td><b>Datum</b></td><td><b>Omschrijving;</b></td><td><b>Gebruiker_ID</b></td></tr>"; // bovenste regel
if ($resultaat) {
while ($rij = mysql_fetch_array($resultaat)) {
echo "<tr>";
echo "<td>".$rij['Probleem_ID']."</td>";
echo "<td>".$rij['Categorie_ID']."</td>";
echo "<td>".$rij['Datum']."</td>";
echo "<td>".$rij['Probleem']."</td>";
echo "<td>".$rij['Gebruiker_ID']."</td>";
echo "</tr>";
}
}
echo "</table>";
mysql_close($db);
}
?>
<form name="form1" method="post" action="">
<input type="submit" name="Zoek" id="Zoek" value="zoek">
</form>
unless I’ve completely miss understood the question here:
when the form is submitted posting the category id to your script, try the following:
that should then get all your results for that category id, and if its not set, you will get all the results as previously got.