SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Baltimore
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying Results

    I am reading information from a sql db and would like for the information to display, which i had working, until i tried making it so that if there was no information in the db field, that it would not display any results.

    Here is a snippet of the code. Any thoughts.


    if name <> "" then
    Response.Write("Name: " & recordset("name")& "<br>")
    end if

    if company <> "" then
    Response.Write("Company: " & recordset("company")& "<br>")
    end if

    if title <> "" then
    Response.Write("Title: " & recordset("title")& "<br>")
    end if

  2. #2
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you paste your recordset here, it would help

    I prefer to put

    if not recordset.bof and not recordset.eof then
    'do something
    end if
    Am assuming that all 3, name, company and title belong to the same recordset

    Afrika

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Baltimore
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying Results

    I am writing information from a form into a db and have 2 different departments from work that are logging in to view the results. The person filling out the form, might not answer all the questions, therefore, i would like to not display those particular the additional fields, i.e. if htey don't list their title, then it skips that and moves to their company name.




    If recordset.EOF then
    response.Write "There were no records returned."
    end if
    if username = "mktg" then

    response.write("<strong>Contact Information</strong><br>")

    if name <> "" then
    Response.Write("Name: " & recordset("name")& "<br>")
    end if

    if company <> "" then
    Response.Write("Company: " & recordset("company")& "<br>")
    end if

    Quote Originally Posted by afrika
    If you paste your recordset here, it would help

    I prefer to put



    Am assuming that all 3, name, company and title belong to the same recordset

    Afrika

  4. #4
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your code looks ok to me, the only thing i may ask, is that is the username, name and company variables ? and where are they gotten from ?

    Or are they recordsets, or request objects ?

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Baltimore
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying Results

    The username is stored in another table and is being passed via query string. That part is working, the part that isn't, is that data isn't being read from the db.

    The name and company name variables are coming from a web form and being stored in a db table.



    Quote Originally Posted by afrika
    Your code looks ok to me, the only thing i may ask, is that is the username, name and company variables ? and where are they gotten from ?

    Or are they recordsets, or request objects ?

  6. #6
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    then use
    request.form("name")
    or request.form("company")

    etc
    if coming from the web form

    isn't, is that data isn't being read from the db.
    paste your code and db structure here

  7. #7
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Baltimore
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying Results

    Here is the entire code:


    <%
    Dim connection, recordset
    Dim SQL, sConnString, username
    Dim name, company, title,address, address2, city, state, zip, phone, fax, industry, industry_other, email, attendees, totalprice, name1, title1, email1,name2, title2, email2,name3, title3, email3,name4, title4, email4,name5, titel5, email5,rdate, payment, card,expiration, yes_no,b_name,b_address,b_address2,b_city,b_state,b_zip,b_signature
    SQL = "SELECT * FROM ACCOUNT ORDER by company"

    sConnString = "Driver={SQL Server};Server=xxxxx;Database=xxxxxx;Uid=xxxxxx;Pwd=xxxx;"

    Set connection = Server.CreateObject("ADODB.Connection")
    Set recordset = Server.CreateObject("ADODB.Recordset")

    connection.Open sConnString

    recordset.Open SQL,connection

    do while NOT recordset.EOF

    If recordset.EOF then
    response.Write "There were no records returned."
    end if

    if username = "mktg" then

    response.write("<strong>Contact Information</strong><br>")

    Request.Form("name")
    if name <> "" then
    Response.Write("Name: " & recordset("name")& "<br>")
    end if

    if company <> "" then
    Response.Write("Company: " & recordset("company")& "<br>")
    end if

    if title <> "" then
    Response.Write("Title: " & recordset("title")& "<br>")
    end if

    if address <> "" then
    Response.Write("Address: " & recordset("address")& "<br>")
    end if

    if address2 <> "" then
    Response.Write("Address: " & recordset("address2")& "<br>")
    end if

    if city <> "" then
    Response.Write("City: " & recordset("city")& "<br>")
    end if

    if state <> "" then
    Response.Write("State: " & recordset("state")& "<br>")
    end if

    if zip <> "" then
    Response.Write("Zip: " & recordset("zip")& "<br>")
    end if

    if phone <> "" then
    Response.Write("Phone: " & recordset("phone")& "<br>")
    end if

    if fax <> "" then
    Response.Write("Fax: " & recordset("fax")& "<br>")
    end if

    if industry <> "" then
    Response.Write("Industry: " & recordset("industry")& "<br>")
    end if

    if industry_other <> "" then
    Response.Write("Other Industry: " & recordset("industry_other")& "<br>")
    end if

    if email <> "" then
    Response.Write("Email: " & recordset("email")& "<br>")
    end if

    if attendees <> "" then
    Response.Write("Attendees: " & recordset("attendees")& "<br>")
    end if

    if totalprice <> "" then
    Response.Write("Total Price: " & formatcurrency(recordset("totalprice"))& "<br>")
    end if

    response.write("<strong>Additional Attendees</strong><br>")

    if name1 <> "" then
    Response.Write("Name: " & recordset("name1")& "<br>")
    end if

    if title1 <> "" then
    Response.Write("Title: " & recordset("title1")& "<br>")
    end if

    if email1 <> "" then
    Response.Write("Email: " & recordset("email1")& "<br>")
    end if

    if name2 <> "" then
    Response.Write("Name: " & recordset("name2")& "<br>")
    end if

    if title2 <> "" then
    Response.Write("Title: " & recordset("title2")& "<br>")
    end if

    if email3 <> "" then
    Response.Write("Email: " & recordset("email3")& "<br>")
    end if

    if name4 <> "" then
    Response.Write("Name: " & recordset("name4")& "<br>")
    end if

    if title4 <> "" then
    Response.Write("Title: " & recordset("title4")& "<br>")
    end if

    if email4 <> "" then
    Response.Write("Email: " & recordset("email4")& "<br>")
    end if

    if name5 <> "" then
    Response.Write("Name: " & recordset("name5")& "<br>")
    end if

    if titel5 <> "" then
    Response.Write("Title: " & recordset("title5")& "<br>")
    end if

    if email5 <> "" then
    Response.Write("Email: " & recordset("email5")& "<br>")
    end if

    if rdate <> "" then
    Response.Write("Date: " & recordset("rdate")& "<br>")
    end if

    end if
    if username = "acct" then

    response.write("<strong>Contact Information</strong><br>")
    if name <> "" then
    Response.Write("Name: " & recordset("name")& "<br>")
    end if

    if company <> "" then
    Response.Write("Company: " & recordset("company")& "<br>")
    end if

    if title <> "" then
    Response.Write("Title: " & recordset("title")& "<br>")
    end if

    if address <> "" then
    Response.Write("Address: " & recordset("address")& "<br>")
    end if

    if address2 <> "" then
    Response.Write("Address: " & recordset("address2")& "<br>")
    end if

    if city <> "" then
    Response.Write("City: " & recordset("city")& "<br>")
    end if

    if state <> "" then
    Response.Write("State: " & recordset("state")& "<br>")
    end if

    if zip <> "" then
    Response.Write("Zip: " & recordset("zip")& "<br>")
    end if

    if phone <> "" then
    Response.Write("Phone: " & recordset("phone")& "<br>")
    end if

    if fax <> "" then
    Response.Write("Fax: " & recordset("fax")& "<br>")
    end if

    if email <> "" then
    Response.Write("Email: " & recordset("email")& "<br>")
    end if

    if attendees <> "" then
    Response.Write("Attendees: " & recordset("attendees")& "<br>")
    end if

    if totalprice <> "" then
    Response.Write("Total Price: " & formatcurrency(recordset("totalprice"))& "<br>")
    end if

    response.write("<strong>Additional Attendees</strong><br>")

    if name1 <> "" then
    Response.Write("Name: " & recordset("name1")& "<br>")
    end if

    if title1 <> "" then
    Response.Write("Title: " & recordset("title1")& "<br>")
    end if

    if email1 <> "" then
    Response.Write("Email: " & recordset("email1")& "<br>")
    end if

    if name2 <> "" then
    Response.Write("Name: " & recordset("name2")& "<br>")
    end if

    if title2 <> "" then
    Response.Write("Title: " & recordset("title2")& "<br>")
    end if

    if email3 <> "" then
    Response.Write("Email: " & recordset("email3")& "<br>")
    end if

    if name4 <> "" then
    Response.Write("Name: " & recordset("name4")& "<br>")
    end if

    if title4 <> "" then
    Response.Write("Title: " & recordset("title4")& "<br>")
    end if

    if email4 <> "" then
    Response.Write("Email: " & recordset("email4")& "<br>")
    end if

    if name5 <> "" then
    Response.Write("Name: " & recordset("name5")& "<br>")
    end if

    if titel5 <> "" then
    Response.Write("Title: " & recordset("title5")& "<br>")
    end if

    if email5 <> "" then
    Response.Write("Email: " & recordset("email5")& "<br>")
    end if


    response.write("<strong>Billing Information</strong><br>")
    if payment <> "" then
    Response.Write("Payment: " & recordset("payment")& "<br>")
    end if

    if card <> "" then
    Response.Write("Card: " & recordset("card")& "<br>")
    end if

    if expiration <> "" then
    Response.Write("Expiration: " & recordset("expiration")& "<br>")
    end if

    if yes_no <> "" then
    Response.Write("Billing Information the same?: " & recordset("yes_no")& "<br>")
    end if

    if b_name <> "" then
    Response.Write("Billing Name: " & recordset("b_name")& "<br>")
    end if

    if b_address <> "" then
    Response.Write("Billing Address: " & recordset("b_address")& "<br>")
    end if

    if b_address2 <> "" then
    Response.Write("Billing Address: " & recordset("b_address2")& "<br>")
    end if

    if b_city <> "" then
    Response.Write("Billing City: " & recordset("b_city")& "<br>")
    end if

    if b_state <> "" then
    Response.Write("Billing State: " & recordset("b_state")& "<br>")
    end if

    if b_zip <> "" then
    Response.Write("Billing Zip: " & recordset("b_zip")& "<br>")
    end if

    if b_signature <> "" then
    Response.Write("Signature: " & recordset("b_signature")& "<br>")
    end if

    if rdate <> "" then
    Response.Write("Date: " & recordset("rdate")& "<br>")
    end if
    end if

    Response.Write("<br>")
    Response.Write("<br>")

    recordset.MoveNext
    loop



    Recordset.Close
    Set Recordset = nothing
    Connection.Close
    Set Connection = nothing
    %>



    Quote Originally Posted by afrika
    then use
    request.form("name")
    or request.form("company")

    etc
    if coming from the web form


    paste your code and db structure here

  8. #8
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your code is quite lenghty

    :-)

  9. #9
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    however there are somethings i really dont understand here e.g
    Code:
    <%
    Dim connection, recordset
    Dim SQL, sConnString, username
    Dim name, company, title,address, address2, city, state, zip, phone, fax, industry, industry_other, email, attendees, totalprice, name1, title1, email1,name2, title2, email2,name3, title3, email3,name4, title4, email4,name5, titel5, email5,rdate, payment, card,expiration, yes_no,b_name,b_address,b_address2,b_city,b_state,b_zip,b_signature
    SQL = "SELECT * FROM ACCOUNT ORDER by company"
    
    sConnString = "Driver={SQL Server};Server=xxxxx;Database=xxxxxx;Uid=xxxxxx;Pwd=xxxx;" 
    
    Set connection = Server.CreateObject("ADODB.Connection")
    Set recordset = Server.CreateObject("ADODB.Recordset")
    
    connection.Open sConnString
    
    recordset.Open SQL,connection
    
    do while NOT recordset.EOF
    
    If recordset.EOF then
    response.Write "There were no records returned."
    end if 
    
    if username   = "mktg" then 
    
    response.write("<strong>Contact Information</strong><br>")
    
    Request.Form("name")
    if name <> "" then 
    Response.Write("Name: " & recordset("name")& "<br>")
    end if 
    
    if company <> "" then 
    Response.Write("Company: " & recordset("company")& "<br>")
    end if 
    
    if title <> "" then
    Response.Write("Title: " & recordset("title")& "<br>")
    end if 
    
    if address <> "" then
    Response.Write("Address: " & recordset("address")& "<br>")
    end if 
    
    if address2 <> "" then
    Response.Write("Address: " & recordset("address2")& "<br>")
    end if 
    
    if city <> "" then
    Response.Write("City: " & recordset("city")& "<br>")
    end if 
    
    if state <> "" then
    Response.Write("State: " & recordset("state")& "<br>")
    end if
    Where are the values of the above variables gotten from

  10. #10
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Baltimore
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying Results

    The username is be checked via a querystring. That part works too, b/c I am getting the correct layout and report information for each department, just not the results.



    Quote Originally Posted by afrika
    however there are somethings i really dont understand here e.g
    Code:
    <%
    Dim connection, recordset
    Dim SQL, sConnString, username
    Dim name, company, title,address, address2, city, state, zip, phone, fax, industry, industry_other, email, attendees, totalprice, name1, title1, email1,name2, title2, email2,name3, title3, email3,name4, title4, email4,name5, titel5, email5,rdate, payment, card,expiration, yes_no,b_name,b_address,b_address2,b_city,b_state,b_zip,b_signature
    SQL = "SELECT * FROM ACCOUNT ORDER by company"
    
    sConnString = "Driver={SQL Server};Server=xxxxx;Database=xxxxxx;Uid=xxxxxx;Pwd=xxxx;" 
    
    Set connection = Server.CreateObject("ADODB.Connection")
    Set recordset = Server.CreateObject("ADODB.Recordset")
    
    connection.Open sConnString
    
    recordset.Open SQL,connection
    
    do while NOT recordset.EOF
    
    If recordset.EOF then
    response.Write "There were no records returned."
    end if 
    
    if username   = "mktg" then 
    
    response.write("<strong>Contact Information</strong><br>")
    
    Request.Form("name")
    if name <> "" then 
    Response.Write("Name: " & recordset("name")& "<br>")
    end if 
    
    if company <> "" then 
    Response.Write("Company: " & recordset("company")& "<br>")
    end if 
    
    if title <> "" then
    Response.Write("Title: " & recordset("title")& "<br>")
    end if 
    
    if address <> "" then
    Response.Write("Address: " & recordset("address")& "<br>")
    end if 
    
    if address2 <> "" then
    Response.Write("Address: " & recordset("address2")& "<br>")
    end if 
    
    if city <> "" then
    Response.Write("City: " & recordset("city")& "<br>")
    end if 
    
    if state <> "" then
    Response.Write("State: " & recordset("state")& "<br>")
    end if
    Where are the values of the above variables gotten from

  11. #11
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Baltimore
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying Results

    i figured it out. and as i suspected, it was an easy fix.
    it should have been if recordset("name") <> " then

    thanks for the help.

    Quote Originally Posted by jleggett
    The username is be checked via a querystring. That part works too, b/c I am getting the correct layout and report information for each department, just not the results.

  12. #12
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You do know, its gonna be easier doing the following:

    Code:
    <% 
    
    for each item in request.form
    if request.form(item) <> "" then
    response.write item & "=" & request.form(item)
    end if
    next
    
    %>
    This will loop through all your form collection and display it in the page. If you want to exclude any hidden forms etc, all you need to do is add another if statement.

    Gav


Bookmarks

Posting Permissions

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