...

View Full Version : Writing the value of current Loop



coocoobird
01-04-2008, 06:07 PM
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

shyam
01-04-2008, 06:14 PM
Onclick="<&#37; Session("SelectedProfile") = " & TheUser & " %>"


maybe u should try


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

coocoobird
01-04-2008, 11:25 PM
maybe u should try


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?

Spudhead
01-07-2008, 11:40 AM
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.

coocoobird
01-08-2008, 03:55 PM
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.

Spudhead
01-08-2008, 05:06 PM
Not really :D

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


"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:

SELECT user_name FROM users

and then loop through your recordset writing out link tags like:


response.write("<a href=""viewprofile.asp?username=""" & myRecordset.fields("user_name").value & """>clicky</a>")

Does that make any sense?

coocoobird
01-08-2008, 07:22 PM
Not really :D

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


"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:

SELECT user_name FROM users

and then loop through your recordset writing out link tags like:


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 :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum