Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb Writing the value of current Loop

    What i am doing is looping through a database. If it matches certain criteria then i will put a table with values from that person on the page. My question is i need to get the current value of lets say varible TheUser and write it to the html line. Here is what i have which is not working ofcourse =)


    If i do it this way it just puts whats in the quotes after =

    Onclick="<% Session("SelectedProfile") = " & TheUser & " %>"

    If i do it this way it gets the last user that it looped through.

    Onclick="<% Session("SelectedProfile") = TheUser %>"

    I figure i am close lol

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by coocoobird View Post
    Onclick="<&#37; Session("SelectedProfile") = " & TheUser & " %>"
    maybe u should try
    Code:
    onclick="<%= Session("SelectedProfile") =TheUser %>"
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by shyam View Post
    maybe u should try
    Code:
    onclick="<%= Session("SelectedProfile") =TheUser %>"
    thats still just giving me the last value the TheUser has, I am trying to have it a different value for each time its used.. because its going to be pointing to a different users directory. if that makes sense?

  • #4
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Ok, two questions. First, where are you getting this variable "TheUser" from? From your database? Can you post the whole chunk of code that you're using for this?

    Second - what, exactly, are you trying to do? Set an ASP session variable on a click? Because that's not going to work: click events fire client-side, but you need server-side code to set a session variable.

  • #5
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Spudhead View Post
    Ok, two questions. First, where are you getting this variable "TheUser" from? From your database? Can you post the whole chunk of code that you're using for this?

    Second - what, exactly, are you trying to do? Set an ASP session variable on a click? Because that's not going to work: click events fire client-side, but you need server-side code to set a session variable.

    I didnt even think about the client-side and server-side part.. bah..

    I am looping through a database and getting all the usernames in it. If the users info matches what the user did a search for it will paste that matching user information on the html page. Its basically a profile. So what im trying to do is know what user that has been selected once all the search is complete. I know that i can make a (viewprofile.asp) page under all the users directories and have it point to that.. but what i wanted to refrain from was to have to do that and only use one page to save space and time. Hope this explains it.

  • #6
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Not really

    Why would you get ALL the users from the database? Why not just get the user that's being searched for? Like:

    Code:
    "SELECT * FROM users WHERE user_name = '" & strUserToLookFor & "'"

    (although using * isn't a very good idea, you should ideally name the fields you want)


    Make your database do the heavy lifting, that's what its there for.

    That would be the query to write your viewprofile.asp page - if you wanted to list your users, you could:
    Code:
    SELECT user_name FROM users
    and then loop through your recordset writing out link tags like:

    Code:
    response.write("<a href=""viewprofile.asp?username=""" & myRecordset.fields("user_name").value & """>clicky</a>")
    Does that make any sense?

  • #7
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Spudhead View Post
    Not really

    Why would you get ALL the users from the database? Why not just get the user that's being searched for? Like:

    Code:
    "SELECT * FROM users WHERE user_name = '" & strUserToLookFor & "'"

    (although using * isn't a very good idea, you should ideally name the fields you want)


    Make your database do the heavy lifting, that's what its there for.

    That would be the query to write your viewprofile.asp page - if you wanted to list your users, you could:
    Code:
    SELECT user_name FROM users
    and then loop through your recordset writing out link tags like:

    Code:
    response.write("<a href=""viewprofile.asp?username=""" & myRecordset.fields("user_name").value & """>clicky</a>")
    Does that make any sense?
    well that got me in the right direction. But what i did to fix the problem finally...... hehe .. i couldnt remember how to pass a varible through an html click.. until i seen your link code.. the ? reminded me that i just needed to pass the varible like so.

    href="Http://www.Someplace.com/profiles/ViewProfile.asp?UserName=<% Response.write(TheUser) %>" ><% Response.write(GetProfileTitle) %>


    Then on the ONE viewprofile page i just grab the varible that was passed. Like So

    Dim UserName
    UserName = Trim(Request("UserName"))

    And walla i finally know what user was clicked easily lol.. thanks for the help and suggestions


  •  

    Posting Permissions

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