I have been eyeballing this for a long time and I'm missing something. I know the function is good because if I call it on a page with just a select box it performs like I want it to. I'm just having a hard time calling the function in the echo.
There could be an issue in my HTML too. Below you find a snippet of the function and where I want to call the function. Thank you in advance for any help.
//this function creates optgroup for subcategory in a select box
function groupSubcatName(){
$sql="SELECT * FROM subcategory INNER JOIN category ON subcategory.subcat_cat = category.cat_id";
$result=mysql_query($sql);
$result = mysql_query($sql);
$group = array();
while ($row = mysql_fetch_assoc($result))
{
$group[$row['cat_name']][] = $row;
}
foreach ($group as $key => $values)
{
echo '<optgroup label="'.$key.'">';
foreach ($values as $value)
{
echo '<option value="'.$value['subcat_name'].'">'.$value['subcat_name'].'</option>';
}
echo '</optgroup>';
}
}
//below you will find the select with the called function
if($_SERVER['REQUEST_METHOD'] != 'POST'){
echo '<form method="post" action="">
<label for ="PostSubject">Subject: </label>
<input name="post_subject" type="text" size="105" /><br /><br />
<label for="PostContent">Content: </label>
<textarea rows="20" cols="80" name="post_content" /></textarea><br /><br />
<label for="PostSubcategory">Subcategory: </label>
<select name="post_subcat">
<option value=0>Choose</option>
'.groupSubcatName().';
</option>
</select><br /><br />
<input type="submit" value="Create Post" />
</form>';
}