DEV Community

Laurens van Oorschot
Laurens van Oorschot

Posted on

How do I get the selected value of the second dropdown from the first dropdown via MY-SQL?

I am building an editor for a blog. Each post will be categorised. I am trying to get all the posts, with the category that they have been assigned to be displayed as dropdown menu. So, when the user clicks on a post title from the first dropdown menu, then the second category dropbox will have the selected category associated with it, and display all the other categories in the same dropbox. So. user can change the category of article. I am struggling with it and don't know what I am doing wrong. Can anyone help?

                if(isset($_POST['Ga'])) {
                      $db = new mysqli("160.153.129.204", "laurensvo92", "90F0411553l", "lvo92");//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("160.153.129.204", "laurensvo92", "90F0411553l", "lvo92");

  $db = new mysqli("160.153.129.204", "laurensvo92", "90F0411553l", "lvo92");//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>

    <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);


  }

?>
         <input id='Ga' type='submit'  value='Ga'name='Ga' />

Top comments (0)