Results 1 to 3 of 3

Thread: ASP code HELP!

  1. #1
    Join Date
    Jul 2003
    Posts
    1

    Unanswered: ASP code HELP!

    Hi all, I'm hoping that someone out there can help me

    Here's the task... I need to manipulate some code (see below) so I can attribute a background color to a set of categories/subcategories. I will add a column to the categoreies table in access in order to specify the color - i.e. #ffffff

    But I need some help to edit the code - to call the new field 'catbgcolor' which will be a TD attribute - i.e. normally <TD BGCOLR=#FFFFFF>

    Object is to color code my category links to make site navigation easier

    Any help would be appreciated

    Dave

    Here's the code:
    ------------------------------------
    dim dbc
    shoppageheader
    shopopendatabase dbc
    Displaycategories
    shopclosedatabase dbc
    shoppagetrailer

    '************************************************* **************************
    sub Displaycategories
    dim sql, rs, level, rc, catdescription, spacing, categoryid
    dim highercategoryid, hassubcategory
    highercategoryid=0
    Generatesql sql, highercategoryid
    set rs=dbc.execute(sql)
    CreateCattable
    do while not rs.eof
    Getcategoryfields rs,categoryid, hassubcategory, catdescription, rc
    If rc=0 then
    spacing=0
    Formatcategory categoryid, catdescription, spacing
    If hassubcategory<>"" then
    Formatsubcategories categoryid,spacing
    end if
    end if
    rs.movenext
    loop
    closerecordset rs
    Response.write "</td></tr></table>"
    end sub

    Sub Createcattable
    Response.write "<table width='60%'>"
    response.write "<tr>"
    response.write "<td align=left>"
    end sub
    '
    Sub Getcategoryfields (rs, categoryid, hassubcategory, strcategory, rc)
    dim strcathide
    categoryid=rs("categoryid")
    strcategory=rs("catdescription")
    hassubcategory=rs("hassubcategory")
    If isnull(hassubcategory) then
    hassubcategory=""
    end if
    strcathide=rs("cathide") ' hide field
    if isnull(strcathide) then
    rc=0
    else
    rc=4
    end if
    end sub

    Sub Generatesql (sql, highercategoryid)
    SQL="Select * from categories "
    sql = Sql & " where highercategoryid=" & highercategoryid
    if getconfig("xproductmatch")="Yes" then
    sql=sql & " and productmatch='" & xproductmatch & "'"
    end if
    if getconfig("xproductmatchcustomer")="Yes" then
    if GetSess("CustomerProductGroup")<>"" then
    sql=sql & " and customermatch='" & getsess("customerProductgroup") & "'"
    end if
    end if
    Handle_selectcategoriesbylanguage sql
    sql=sql & " order by " & Getconfig("xsortcategories")
    end sub

    Sub Formatcategory (id, name, spacing)
    dim i
    If spacing>0 then
    for i = 0 to spacing
    response.write "&nbsp;&nbsp;"
    next
    end if
    response.write "<a HREF=""shopdisplayproducts.asp?id=" & id & "&amp;cat=" & Server.URLEncode(name) & """>" & name & "</a>" & "<br>" & vbcrlf
    end sub

    Sub Formatsubcategories (categoryid, spacing)
    dim sql, rs, rc, catdescription, hassubcategory
    Generatesql sql, categoryid
    Set rs=dbc.execute(sql)
    spacing=spacing+1
    do while not rs.eof
    Getcategoryfields rs,categoryid, hassubcategory, catdescription, rc
    If rc=0 then
    Formatcategory categoryid, catdescription, spacing
    If hassubcategory<>"" then
    Formatsubcategories categoryid, spacing
    end if
    end if
    rs.movenext
    loop
    spacing=spacing-1
    closerecordset rs
    end sub

    sub Handle_selectcategoriesbylanguage (sql)
    If getconfig("xselectproductsbylanguage")="Yes" and getsess("language")<>"" then
    sql=sql & " and (catlanguage='" & getsess("language") & "'"
    sql=sql & " or catlanguage is null)"
    end if
    end sub
    %>

    -----------------------------------------
    Last edited by davec99; 07-02-03 at 17:43.

  2. #2
    Join Date
    Feb 2002
    Location
    San Francisco, CA
    Posts
    441
    This is really easy to do, but its late, your code is badly formatted and I just can't take it all in right now;

    basically what you need to do is to find the bit where the fields are read from the record set (and where they are outputted) and modify the code accordingly.

    Easiest way would be to find the person who wrote this...Trust me it really should be very simple. I am just sooooo tired (sorry)

  3. #3
    Join Date
    Jul 2003
    Posts
    3
    Code is confusing...umm it looks like your table code will be:
    <table width=60%>
    <tr>
    <td align=left>

    ...loop through all links here

    </td>
    </tr>
    </table>

    if this is the case you only have one table cell. you need a </td></tr><tr><td> every time you want to create a new cell with a new background color. So put that in your loop somewhere... Then to get your background color do something like
    Response.Write("<TD bgcolor=" & rs.Fields("tablebackgroundcolor") & ">")
    instead of tablebackgroundcolor put whatever the field name is with the color in it...i think that should do it i'm too lazy to look up the exact commands right now...actually i'm surprised that code works with some of the stuff it does. oh well whatever works...good luck
    Compaq

Posting Permissions

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