Results 1 to 4 of 4
  1. #1
    Join Date
    May 2006
    Posts
    2

    Unanswered: Dropdown Not Populating Correctly

    Hi All,

    I'm joining two tables. A product table and an options table. The options table has a column for different sizes for each product. I'm trying to populate a web form dropdown with the sizes. But the dropdown will only display the first size and repeat that first size. So if I have small, medium, and large, the dropdown will only have "small" 3 times.

    Product Table
    --------------
    ID | Name | Description
    1 widget the best product

    Options Table
    -------------
    ID | Size | Inventory
    1 small 5
    1 medium 1
    1 large 2


    rs.Source = "SELECT P.id, P.name, P.description, O.id, O.size, O.Inventory FROM Product LEFT JOIN Options ON P.id = O.id AND O.id = '" & QueryStringID & "' WHERE P.id = '" & QueryStringID & "'ORDER BY P.id ASC"

    Dim strDropList
    While NOT rs.EOF
    strDropList = strDropList & "<option value='" & strSize1 & "'>" & strSize1 & "</option>"
    rs.MoveNext
    Wend

    Response.Write "<p><select size='1' name='drop'>"
    Response.Write strDropList
    Response.Write "</select></p>"

    Let me know if you need any more info. Thanks.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    in your query, you are joining the tables on P.id = O.id

    therefore if you specify P.id equal to some QueryStringID in the WHERE clause, then you do not also have to make O.id equal to the same QueryStringID, because it's gonna only ever be equal to P.id

    as far as why you're displaying only one size, that's a problem with your script, not mysql, so i'm going to move that thread over to the asp forum (i hope that's what that "movenext" language is)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    May 2006
    Posts
    2
    Oops, the Where clause was used just to get the table to populate with only those 3 rows matched with the ID. Just for me to see it visually. But the query without the Where clause is my normal query.

    I've used the same query on Oracle and it worked ok. Yes, ASP is used to write out the dropdowns. But is my "query" incorrect for mysql? Sorry, I thought that would make it a mysql-related question.

    And I am a bit of a noob. So please be kind


    Quote Originally Posted by r937
    in your query, you are joining the tables on P.id = O.id

    therefore if you specify P.id equal to some QueryStringID in the WHERE clause, then you do not also have to make O.id equal to the same QueryStringID, because it's gonna only ever be equal to P.id

    as far as why you're displaying only one size, that's a problem with your script, not mysql, so i'm going to move that thread over to the asp forum (i hope that's what that "movenext" language is)

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    your query is fine
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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