I created the sub below to obtain the product types of the products table in my shop database and then display it as a drop down box for the web user to select. It all works fine if there is a one phrase only in the product type field. However, I have several records that may have more than one product type in the same field (type) separated by a comma.
The way it builds the drop down box is by reading all records, selecting the distinct value of the 'type' field, sorting them and then building the drop down box with all disctinct values.
How can I check whether my 'type' field has one or more types, then select only the distict values and display them all as a drop down box? hopefully i can just incorporate code into what I already ahve below.
Thanks for all your help.
Sub AddProductTypes
dim name,catSQL, catrs
catSQL="SELECT DISTINCT products.type"
catSQL=catSQL & " FROM products INNER JOIN (categories INNER JOIN prodcategories ON categories.categoryid = prodcategories.intcategoryid) ON products.catalogid = prodcategories.intcatalogid"
catSQL=catSQL & " WHERE (((products.type) Is Not Null) AND ((categories.categoryid)="& cat_id &") AND ((products.hide)=No))"
catSQL=catSQL & " ORDER BY products.type"
set catrs=dbc.execute(catsql)
Response.Write "<select size=""1"" class=""txtfielddropdown"" name=""SelectValue"">"
Response.Write "<option></option>False"
While Not catrs.EOF
name=catrs("type")
Response.Write "<option value=" & name & ">" & name & "</option>"
catrs.MoveNext
Wend
Response.Write "</select>"
catrs.Close
set catrs=nothing
end sub
The way it builds the drop down box is by reading all records, selecting the distinct value of the 'type' field, sorting them and then building the drop down box with all disctinct values.
How can I check whether my 'type' field has one or more types, then select only the distict values and display them all as a drop down box? hopefully i can just incorporate code into what I already ahve below.
Thanks for all your help.
Sub AddProductTypes
dim name,catSQL, catrs
catSQL="SELECT DISTINCT products.type"
catSQL=catSQL & " FROM products INNER JOIN (categories INNER JOIN prodcategories ON categories.categoryid = prodcategories.intcategoryid) ON products.catalogid = prodcategories.intcatalogid"
catSQL=catSQL & " WHERE (((products.type) Is Not Null) AND ((categories.categoryid)="& cat_id &") AND ((products.hide)=No))"
catSQL=catSQL & " ORDER BY products.type"
set catrs=dbc.execute(catsql)
Response.Write "<select size=""1"" class=""txtfielddropdown"" name=""SelectValue"">"
Response.Write "<option></option>False"
While Not catrs.EOF
name=catrs("type")
Response.Write "<option value=" & name & ">" & name & "</option>"
catrs.MoveNext
Wend
Response.Write "</select>"
catrs.Close
set catrs=nothing
end sub