...

View Full Version : help with php sql join forum with dropdown



winracer
09-20-2011, 06:23 PM
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..




$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
09-20-2011, 08:17 PM
thanks but I think I got it



?>
<!--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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum