Click here to Skip to main content
14,550,567 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am building an editor for a blog and 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 page reloads with the second category dropbox selected to the category associated with it, and display all the other categories in the same dropbox.

The second dropbox that contains all the categories will allow the user to change the category of article. I am able to get both dropboxes populated, but I don't know how to get the selection part working.

I think that the (isset($_POST['Ga'])) is missing something, but I don't know.
Any suggestions?
<?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);
           $resultofcat = 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()) {
    	  $resultofcat = ("<option value='{$row ['catid']}'> {$row['cat']}</option>");
          echo $resultofcar;
        }
      ?>

    </select>

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


What I have tried:

I have tried searching through Stackoverflow with no luck and tried asking this question there, but haven't received any responses.
Posted
Updated 22-May-20 10:31am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100