Click here to Skip to main content
15,891,881 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
<?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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900