Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2009
    Location
    Georgia
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    help with php sql join forum with dropdown

    I have this code below and I have category and subcategory. I would like to join the dropdown option on category id and subcategory category

    and have one dropdown plus have the subcategory display under the category like:

    category
    --subcategory
    category1
    --subcategory1

    etc..


    Code:
    $sql = "SELECT
    					id,
    					name,
    					description
    				FROM
    					category";
    		
    		$result = mysql_query($sql);
    
    
    $sql5 = "SELECT
    					id,
    					category,
    					name,
    					description
    				FROM
    					subcategory";
    		
    		$result5 = mysql_query($sql5);
    
    
    
    
    
    echo "<form action='post.php' method='post'>";
       //echo "<p><label for=\"name\">Name:</label><textarea name=\"name\" id=\"name\" style=\"width: 30%; height: 20px;\"></textarea></p>";
       echo "<p><label for=\"subject\">Subject:</label><textarea name=\"subject\" id=\"subject\" style=\"width: 40%; height: 20px;\"></textarea></p>";
       echo "<p><label for=\"post\">Post:</label><textarea name=\"yourpost\" id=\"post\" style=\"width: 70%; height: 150px;\"></textarea></p>";
      echo "Category: " ;
    echo '<select name="topic_cat">';
    					while($row = mysql_fetch_assoc($result))
    					{
    						echo '<option value="' . $row['id'] . '">' . $row['name'] . '</option>';
    				
    }
    				echo '</select><br />';	
    
    
    
     echo "SubCategory: " ;
    echo '<select name="topic_subcat">';
    					while($row = mysql_fetch_assoc($result5))
    					{
    						echo '<option value="' . $row['id'] . '">' . $row['name'] . '</option>';
    					}
    				echo '</select><br />';	
    
    
    
    
    
     echo "<input type='submit' name='submit' value='submit'></form>";

    thanks for your help
    Winracer
    Jack of all trades master of none :eek:
    http://www.helpmewithperl.com:D
    http://www.myfunnypets.com:D

  • #2
    New Coder
    Join Date
    Apr 2009
    Location
    Georgia
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts
    thanks but I think I got it

    Code:
     ?>
    <!--category-->
    <tr>
     <td style="font-family:verdana;color:gray;font-size:.8pc;font-weight:bold;"width = 50%>Category:</td>
     <td width = 50%>
     <?php
     $ddone = @mysql_query("SELECT id, name FROM myphpforum_category");
     echo "<select name = 'maincat'>";
     while($row = mysql_fetch_assoc($ddone)){
     $catid = $row['id'];
     $catname = $row['name'];
     echo "<option value = \"$catid\"> $catname </option>";
    //--category ends--
    
     //--subcategory--
     $ddtwo = @mysql_query("SELECT id,category,name FROM myphpforum_subcategory WHERE category = $catid");
     //echo "<select name = 'subcat'>";
     while($now = mysql_fetch_assoc($ddtwo)){
     $subcatid = $now['id'];
     $subcatcategory = $now['category'];
    $subcatname = $now['name'];
    
     echo "<option value = \"$subcatid\">----$subcatname</option>";
     }
    }
     echo "</select>";
     ?>
     </td>
     </tr>
    <br>
    <?php
    //subcategory ends here
    Winracer
    Jack of all trades master of none :eek:
    http://www.helpmewithperl.com:D
    http://www.myfunnypets.com:D


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •