Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Arrays and DD boxes

    Hi All:

    I am trying to set up a drop-down box in a web page, which gets populated by
    information from a database. I'm using the getrows method to set up the
    values of data to be passed from the form. Something like:

    alldata=objrs.getrows
    numcols=ubound(alldata,1)
    numrows=ubound(alldata,2)
    <%
    for i = 0 to numRows
    response.write "<option value="""
    response.write alldata(0,i)
    response.write """>"
    response.write alldata(0,i)
    response.write "</option>"
    next
    %>

    This is working fine, in terms of passing the correct data. The thing is, I
    would like to change the last response.write so that it displays text other
    than what is coming out of the database. For instance, if the value of
    allData(0,i) = cmo, I would it to appear in the list as Central Missouri.
    I've come close to making it work a couple of times, but just can't seem to
    get it right. Could anyone add a helping hand? I sure would appreciate it.

    TIA

    Steve G


    Steve G Guest

  2. Similar Questions and Discussions

    1. Nesting Arrays within arrays.
      How do i nest an array inside another array? something like array(i).aray2(j); Can I do that?
    2. Help req with arrays
      I want to use arrays in my website (flat file for a guestbook), but despite having read through countless online tutorials on the topic, I just...
    3. boxes ??
      how do i get them boxes back up, ive turned them ff by accident the colour one and the one that shows the 'layers', 'history' an all that, if ye know...
    4. Using arrays for look-ups
      Hi, Just a quick sanity check... Sometimes it's useful to use an array as a kind of reverse lookup. For example, the indexes being productIDs...
    5. 2 SSA boxes for SSA boxes physical redundancy
      Dears, I want some quick help from you all guys as customer now want me to respond as soon as possible......and i think preobably no one in RISC...
  3. #2

    Default Re: Arrays and DD boxes

    How are you mapping "cmo" to "Central Missouri". Do you have a table in
    your database with this information?

    If so, you should be able to bring that information in with the query which
    populates your list. If the full value is the second column in your
    recordset then you would just switch the line to:

    response.write alldata(1,i)


    If not, you'll have to use some other mechanism: if you have relatively few
    of values to map then a "select case" approach would work.

    Tim.


    "Steve G" <steve@nospam.tnccreations.com> wrote in message
    news:OzrDGwIuDHA.2464@TK2MSFTNGP12.phx.gbl...
    > Hi All:
    >
    > I am trying to set up a drop-down box in a web page, which gets populated
    by
    > information from a database. I'm using the getrows method to set up the
    > values of data to be passed from the form. Something like:
    >
    > alldata=objrs.getrows
    > numcols=ubound(alldata,1)
    > numrows=ubound(alldata,2)
    > <%
    > for i = 0 to numRows
    > response.write "<option value="""
    > response.write alldata(0,i)
    > response.write """>"
    > response.write alldata(0,i)
    > response.write "</option>"
    > next
    > %>
    >
    > This is working fine, in terms of passing the correct data. The thing is,
    I
    > would like to change the last response.write so that it displays text
    other
    > than what is coming out of the database. For instance, if the value of
    > allData(0,i) = cmo, I would it to appear in the list as Central Missouri.
    > I've come close to making it work a couple of times, but just can't seem
    to
    > get it right. Could anyone add a helping hand? I sure would appreciate it.
    >
    > TIA
    >
    > Steve G
    >
    >

    Tim Williams Guest

  4. #3

    Default Re: Arrays and DD boxes

    > How are you mapping "cmo" to "Central Missouri". Do you have a table in
    > your database with this information?
    Sounded to me like Steve expected the database to know that Missouri is
    abbreviated as MO. :-)

    --
    Aaron Bertrand
    SQL Server MVP
    [url]http://www.aspfaq.com/[/url]


    Aaron Bertrand [MVP] Guest

  5. #4

    Default Re: Arrays and DD boxes

    No, I am smart enough to know better than that.

    The values in the database are abbreviations for the full text I am trying
    to display. The values are being passed to another page to display data from
    the database related to those values. I am simply trying to display text in
    the drop down box that will make more sense to the viewer than the
    abbreviations. I tried select case, however I am unable to get it to work.
    Instead of showing each of the text descriptions, it is stopping at the
    first item, and displays that description for each of the items in the
    array. For instance, if there are 6 items in the array, it will show the
    first description for all 6 items. It does however, pass the correct value
    to the next page, so at least that part is working correctly.

    Steve G

    "Aaron Bertrand [MVP]" <aaron@TRASHaspfaq.com> wrote in message
    news:OrSbCnJuDHA.1996@TK2MSFTNGP12.phx.gbl...
    > > How are you mapping "cmo" to "Central Missouri". Do you have a table in
    > > your database with this information?
    >
    > Sounded to me like Steve expected the database to know that Missouri is
    > abbreviated as MO. :-)
    >
    > --
    > Aaron Bertrand
    > SQL Server MVP
    > [url]http://www.aspfaq.com/[/url]
    >
    >

    Steve G Guest

  6. #5

    Default Re: Arrays and DD boxes

    You can eliminate all of these questions by showing us your database table
    structure and the sql query you are using to retrieve the data.

    Bob Barrows

    Steve G wrote:
    > No, I am smart enough to know better than that.
    >
    > The values in the database are abbreviations for the full text I am
    > trying to display. The values are being passed to another page to
    > display data from the database related to those values. I am simply
    > trying to display text in the drop down box that will make more sense
    > to the viewer than the abbreviations. I tried select case, however I
    > am unable to get it to work. Instead of showing each of the text
    > descriptions, it is stopping at the first item, and displays that
    > description for each of the items in the array. For instance, if
    > there are 6 items in the array, it will show the first description
    > for all 6 items. It does however, pass the correct value to the next
    > page, so at least that part is working correctly.
    >
    > Steve G
    >
    > "Aaron Bertrand [MVP]" <aaron@TRASHaspfaq.com> wrote in message
    > news:OrSbCnJuDHA.1996@TK2MSFTNGP12.phx.gbl...
    >>> How are you mapping "cmo" to "Central Missouri". Do you have a
    >>> table in your database with this information?
    >>
    >> Sounded to me like Steve expected the database to know that Missouri
    >> is abbreviated as MO. :-)
    >>
    >> --
    >> Aaron Bertrand
    >> SQL Server MVP
    >> [url]http://www.aspfaq.com/[/url]


    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows Guest

  7. #6

    Default Re: Arrays and DD boxes

    Thanks for your response, Bob:

    Database Table:
    Name = region
    field 1 is ID contains values of 1, 2, 3, 4
    field 2 is Description contains values of cmo, swmo, semo, nwmo

    Retrieving data (I've left some of the obvious stuff out such as the
    connection)

    set objRs = server.createobject("ADODB.recordset")
    Query is: "Select distinct description from region"

    Setting up array:

    alldata=objRs.getrows
    numcols=ubound(alldata,1)
    numrows=ubound(alldata,2)

    Populating the drop down box:

    for i = 0 to numRows
    response.write "<option value="""
    response.write alldata(0,i)
    response.write """>"
    response.write alldata(0,i) //// this is where I need to convert the
    data from the database to text descriptions
    response.write "</option>"
    next

    Steve G

    "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    news:%23jDoLfOuDHA.2308@TK2MSFTNGP09.phx.gbl...
    > You can eliminate all of these questions by showing us your database table
    > structure and the sql query you are using to retrieve the data.
    >
    > Bob Barrows
    >
    > Steve G wrote:
    > > No, I am smart enough to know better than that.
    > >
    > > The values in the database are abbreviations for the full text I am
    > > trying to display. The values are being passed to another page to
    > > display data from the database related to those values. I am simply
    > > trying to display text in the drop down box that will make more sense
    > > to the viewer than the abbreviations. I tried select case, however I
    > > am unable to get it to work. Instead of showing each of the text
    > > descriptions, it is stopping at the first item, and displays that
    > > description for each of the items in the array. For instance, if
    > > there are 6 items in the array, it will show the first description
    > > for all 6 items. It does however, pass the correct value to the next
    > > page, so at least that part is working correctly.
    > >
    > > Steve G
    > >
    > > "Aaron Bertrand [MVP]" <aaron@TRASHaspfaq.com> wrote in message
    > > news:OrSbCnJuDHA.1996@TK2MSFTNGP12.phx.gbl...
    > >>> How are you mapping "cmo" to "Central Missouri". Do you have a
    > >>> table in your database with this information?
    > >>
    > >> Sounded to me like Steve expected the database to know that Missouri
    > >> is abbreviated as MO. :-)
    > >>
    > >> --
    > >> Aaron Bertrand
    > >> SQL Server MVP
    > >> [url]http://www.aspfaq.com/[/url]
    >
    >
    >
    > --
    > Microsoft MVP - ASP/ASP.NET
    > Please reply to the newsgroup. This email account is my spam trap so I
    > don't check it very often. If you must reply off-line, then remove the
    > "NO SPAM"
    >
    >

    Steve G Guest

  8. #7

    Default Re: Arrays and DD boxes

    > Database Table:
    > Name = region
    > field 1 is ID contains values of 1, 2, 3, 4
    > field 2 is Description contains values of cmo, swmo, semo, nwmo
    So where does cmo map to Central Missouri?

    --
    Aaron Bertrand
    SQL Server MVP
    [url]http://www.aspfaq.com/[/url]


    Aaron Bertrand - MVP Guest

  9. #8

    Default Re: Arrays and DD boxes

    The text "Central Missouri" does not exist in the database. I think Tim was
    on the right track about using Select Case, but I am unable to figure out
    the syntax for it.

    Tried something like:

    regions = allData(0,i)
    Select Case Regions
    case cmo
    response.write "Central Missouri"
    case swmo
    response.write "Southwest Missouri"
    end select

    But this does not result in what I want.

    Steve G

    "Aaron Bertrand - MVP" <aaron@TRASHaspfaq.com> wrote in message
    news:uLqU6tOuDHA.3224@tk2msftngp13.phx.gbl...
    > > Database Table:
    > > Name = region
    > > field 1 is ID contains values of 1, 2, 3, 4
    > > field 2 is Description contains values of cmo, swmo, semo, nwmo
    >
    > So where does cmo map to Central Missouri?
    >
    > --
    > Aaron Bertrand
    > SQL Server MVP
    > [url]http://www.aspfaq.com/[/url]
    >
    >

    Steve G Guest

  10. #9

    Default Re: Arrays and DD boxes

    > The text "Central Missouri" does not exist in the database. I think Tim
    was
    > on the right track about using Select Case, but I am unable to figure out
    > the syntax for it.
    Or you could just put the text in the database, instead of hard-coding it
    into your ASP page!
    > regions = allData(0,i)
    > Select Case Regions
    > case cmo
    > response.write "Central Missouri"
    Did you try treating "cmo" as a string, instead of a variable name?

    Select Case allData(0,i)
    case "cmo"
    response.write "Central Missouri"

    --
    Aaron Bertrand
    SQL Server MVP
    [url]http://www.aspfaq.com/[/url]


    Aaron Bertrand - MVP Guest

  11. #10

    Default Re: Arrays and DD boxes

    I can't hard code it, since it needs to be dynamic. Eventually, the data
    displayed in the list will change, depending upon how someone gets to the
    page that shows the drop down. The sql will change to a parameter query such
    as:
    "Select distinct description from region where category = someValue"
    At that time, category will be added to the list of fields in the table, and
    the data that appears in the drop down box will be dependent on the where
    clause.

    Yes, I have tried encasing the value in quotes, but I get the same results,
    or maybe better said, no results. Below is the complete code I am trying to
    use currently without the quotes:

    for i = 0 to numRows2
    response.write "<option value="""
    response.write alldata(0,i)
    response.write """>"

    regions = allData(0,i)
    select case regions
    case cmo
    response.write "Central Missouri"
    case fl
    response.write "Florida"
    case ia
    response.write "Iowa"
    case il
    response.write "Illinois"
    case kc
    response.write "Kansas City"
    case ks
    response.write "Kansas"
    case nc
    response.write "North Carolina"
    case ne
    response.write "Nebraska"
    case neks
    response.write "Northeast Kansas"
    case nemo
    response.write "Northeast Missouri"
    case nwks
    response.write "Northwest Kansas"
    case nwmo
    response.write "Northwest Missouri"
    case pa
    response.write "Pennsylvania"
    case sd
    response.write "South Dakota"
    case seks
    response.write "Southeast Kansas"
    case semo
    response.write "Southeast Missouri"
    case sl
    response.write "St. Louis"
    case swks
    response.write "Southwest Kansas"
    case swmo
    response.write "Southwest Missouri"
    case tx
    response.write "Texas"
    end select
    response.write "</option>"
    next



    "Aaron Bertrand - MVP" <aaron@TRASHaspfaq.com> wrote in message
    news:%23RTX51OuDHA.2360@TK2MSFTNGP09.phx.gbl...
    > > The text "Central Missouri" does not exist in the database. I think Tim
    > was
    > > on the right track about using Select Case, but I am unable to figure
    out
    > > the syntax for it.
    >
    > Or you could just put the text in the database, instead of hard-coding it
    > into your ASP page!
    >
    > > regions = allData(0,i)
    > > Select Case Regions
    > > case cmo
    > > response.write "Central Missouri"
    >
    > Did you try treating "cmo" as a string, instead of a variable name?
    >
    > Select Case allData(0,i)
    > case "cmo"
    > response.write "Central Missouri"
    >
    > --
    > Aaron Bertrand
    > SQL Server MVP
    > [url]http://www.aspfaq.com/[/url]
    >
    >

    Steve G Guest

  12. #11

    Default Re: Arrays and DD boxes

    > I can't hard code it, since it needs to be dynamic.

    You're contradicting yourself. The point of a database is so that it can be
    dynamic. Hard-coding it into a SELECT CASE statement on your ASP page is,
    well, hard-coding it.

    --
    Aaron Bertrand
    SQL Server MVP
    [url]http://www.aspfaq.com/[/url]


    Aaron Bertrand - MVP Guest

  13. #12

    Default Re: Arrays and DD boxes

    "Steve G" <steve@nospam.tnccreations.com> wrote in message
    news:uBMgzCPuDHA.3116@tk2msftngp13.phx.gbl...
    > regions = allData(0,i)
    > select case regions
    > case cmo
    > response.write "Central Missouri"
    > case fl
    > response.write "Florida"
    > case ia
    Use the quotes, that is *not* an optional thing. If you don't it will
    try to treat them as variable names. Also use a Case Else and
    Response.End to trap it when there is no match due to a problem. Then
    you will *know* what the current value of regions is, even if it is
    blank. Do it like this......

    regions = allData(0,i)
    select case regions
    case "cmo"
    response.write "Central Missouri"
    case "fl"
    response.write "Florida"
    case else
    response.write "No match, something is wrong!<br>"
    response.write "The current value of Regions is: " &
    regions & "<br>"
    response.end
    end select


    --

    Phillip Windell [CCNA, MVP, MCP]
    WAND-TV (ABC Affiliate)
    [url]www.wandtv.com[/url]


    Phillip Windell Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139