I am building an editor for a blog. Each post will be categorised.
When the user clicks on a post title from the first dropdown menu and presses Ga (go in dutch), then the second category dropbox will have the selected category associated with it, and display all the other categories in the same dropbox.
Having all the categories in the second dropbox will allow the user to change the category of article. I am able to get both dropbox populated, but not getting the selection part working. Can anyone help?
<?php
if (isset($_POST['Ga'])) {
$db = new mysqli("dbhost", "username", "password", "dbname"); //set your database handler
$query = "SELECT c.catid , a.titel , c.cat FROM artikelen a JOIN Categorie c ON c.catid = a.catid where c.catid = a.catid";
$result = $db->query($query);
while ($row = $result->fetch_assoc()) {
if ($row ['a.catid'] = ['c.catid']) {
$selected = ($row['catid'] == $result);
echo "<option value=\"".$row["catid"]."\" ".($selected ? " selected=\"selected\"":"").">".$row["cat"]."</option>";
}
}
}
?>
<?php
$link = mysqli_connect("dbhost", "username", "password", "dbname");
$db = new mysqli("dbhost", "username", "password", "dbname");//set your database handler
$query = "SELECT c.catid , a.titel , c.cat FROM artikelen a JOIN Categorie c ON c.catid = a.catid";
$result = $db->query($query);
echo "<form action='test.php' method='post' enctype='multipart/form-data'>";
?>
<select id='subcatsSelect'>
<?php
// $query = "SELECT catid, cat FROM Categorie";
$result = $db->query($query);
while ($row = $result->fetch_assoc()) {
// $subcats[$row['catid']][] = array("catid" => $row['catid'], "val" => $row['cat']);
echo "<option value='catid'> {$row['titel']}</option>";
}
?>
</select>
<select id='categoriesSelect'>
<?php
$result = $db->query($query);
while ($row = $result->fetch_assoc()) {
$resultofcar = ("<option value='{$row ['catid']}'> {$row['cat']}</option>");
echo $resultofcar;
}
?>
</select>
<input id='Ga' type='submit' value='Ga'name='Ga' />