For some reason I can't seem to figure this out. I am trying to build a dynamic select box but cant seem to get it right. In the sample database layout below you can see that I have it setup to have a unlimited number of sub category's.
ID CatID Name
1 0 Brads Pictures
2 0 Stephs Pictures
3 1 Christmas
4 1 Halloween
5 3 2003
6 3 2004
Now this is what the select box would look like
<select name="CategoryID">
<option value="1">Brads Pictures</option>
<option value="3">- Christmas</option>
<option value="4">- Halloween</option>
<option value="5">-- 2003</option>
<option value="6">-- 2004</option>
<option value="2">Stephs Pictures</option>
</select>
So far this is the code I have which just display the base category's. Can someone help me figure out how to get this correct?
function DisplayPictureCats(fCatID)
fDisplaySelect = ""
fDisplaySelect = "<select size=""1"" name=""CategoryID"">" & vbCrLf
strSql = "SELECT Cat_ID"
strSql = strSql & ", Cat_CatID"
strSql = strSql & ", Cat_Name"
strSql = strSql & " FROM Category"
strSql = strSql & " WHERE Cat_CatID=0"
Set rsf = my_Conn.Execute(strSql)
If rsf.eof or rsf.bof Then
fDisplaySelect = fDisplaySelect & "<option value="""">No Categorys Available</option>" & vbCrLf
Else
fDisplaySelect = fDisplaySelect & "<option value="""">Select Your Category</option>" & vbCrLf
do until rsf.eof or rsf.bof
fDBCatID = rsf("Cat_ID")
fDBCatCatID = rsf("Cat_CatID")
fDBCatName = rsf("Cat_Name")
fDisplaySelect = fDisplaySelect & "<option value=""" & fDBCatID & """"
If cint(fCatID)=cint(fDBCatID) Then
fDisplaySelect = fDisplaySelect & " selected"
End If
fDisplaySelect = fDisplaySelect & ">" & fDBCatName & "</option>" & vbCrLf
rsf.movenext
loop
End If
fDisplaySelect = fDisplaySelect & "</select>" & vbCrLf
DisplayPictureCats = fDisplaySelect
end function