writing links in a loop?

i want to cycle through my db, and there's a field called "PostNum." i want to check if it matches a variable that should increase by 1 each pass. for some reason it doesn't write the links. this is the code for that, i've already opened the db and all that:
[code]
If Not adoRS.EOF Then
Do Until adoRs.EOF
I = I + 1
If adoRs.Fields("PostNum") = I Then
Response.Write ""%><%Response.Write(adoRs.Fields("UserName") & " " & adoRs.Fields("Title"))%>
<%
Else
adoRs.MoveNext
End If
Loop
Else
Response.Write "There are no current post."
End If
[/code]

Comments

  • Hi,

    Hard to tell without the entire code...
    Did you try to place the icrement part like this:

    If Not adoRS.EOF Then
    Do Until adoRs.EOF
    If adoRs.Fields("PostNum") = I Then
    Response.Write ""%>
    <%Response.Write(adoRs.Fields("UserName") & " " & adoRs.Fields("Title"))%>


    <%
    Else
    adoRs.MoveNext
    End If
    I = I + 1
    Loop
    Else
    Response.Write "There are no current post."
    End If

    Also, I'm confused by the usage of <% %> - you should only surround variables, not the entire link string, because that's part of the html, not vbscript.

    Eg.
    <%@ Language=VBScript %>
    <%
    dim msg
    msg = "Hello"
    %>
    ...

    <%=msg%>

    ...

    : i want to cycle through my db, and there's a field called "PostNum." i want to check if it matches a variable that should increase by 1 each pass. for some reason it doesn't write the links. this is the code for that, i've already opened the db and all that:
    : [code]
    : If Not adoRS.EOF Then
    : Do Until adoRs.EOF
    : I = I + 1
    : If adoRs.Fields("PostNum") = I Then
    : Response.Write ""%><%Response.Write(adoRs.Fields("UserName") & " " & adoRs.Fields("Title"))%><%
    : Else
    : adoRs.MoveNext
    : End If
    : Loop
    : Else
    : Response.Write "There are no current post."
    : End If
    : [/code]
    :

    [hr][grey]To err is human, but to really foul things up requires a computer. (Farmers Almanac)[/grey] :-)

  • let me restart my problem lol. i found some other problems that i don't know how to fix. i need to somehow have a counter, but it needs to be "saved". i thought that using application("counter")=application("counter") + 1 would do it, but it is cleared every time. i need to be able to increase the counter in some code and somehow save it, then with the links part, have maybe a for loop after i opened up the database, see if the "PostNum" = I (loop var) and then display some fields as a link. when i add new data to the db, i want something like:
    [code]
    Application("counter") = Application("counter") + 1 'or something
    'like that since that didn't seem to work.
    adoRs.Fields("PostNum") = counter 'i know how to do the db stuff,
    'but not having a counter that will save each time that code is run.
    [/code]
    Then in a different page create links with certain fields.
  • Hiii.... just one more thought...Is that loop working now? I tried something similar somewhere and that was the way I did it.

    I forgot to look at the most basic thing in your code... the Response.write. When you use response write you code the entire string inside asp, so what are those <% %> doing there? Response.write sends everything that is in parentheses (variable and value pairs) to the browser.

    Response.write("Login")

    Ok, I'll try to look at your counter problem later.

    Cheers,

    Lillu

    : let me restart my problem lol. i found some other problems that i don't know how to fix. i need to somehow have a counter, but it needs to be "saved". i thought that using application("counter")=application("counter") + 1 would do it, but it is cleared every time. i need to be able to increase the counter in some code and somehow save it, then with the links part, have maybe a for loop after i opened up the database, see if the "PostNum" = I (loop var) and then display some fields as a link. when i add new data to the db, i want something like:
    : [code]
    : Application("counter") = Application("counter") + 1 'or something
    : 'like that since that didn't seem to work.
    : adoRs.Fields("PostNum") = counter 'i know how to do the db stuff,
    : 'but not having a counter that will save each time that code is run.
    : [/code]
    : Then in a different page create links with certain fields.
    :

    [hr][grey]To err is human, but to really foul things up requires a computer. (Farmers Almanac)[/grey] :-)

  • ok... one more correction:

    Response.Write doesn't take parentheses, so it looks like:

    : Response.write "Login"

    : Hiii.... just one more thought...Is that loop working now? I tried something similar somewhere and that was the way I did it.
    :
    : I forgot to look at the most basic thing in your code... the Response.write. When you use response write you code the entire string inside asp, so what are those <% %> doing there? Response.write sends everything that is in parentheses (variable and value pairs) to the browser.
    :
    : Response.write("Login")
    :
    : Ok, I'll try to look at your counter problem later.
    :
    : Cheers,
    :
    : Lillu
    :
    : : let me restart my problem lol. i found some other problems that i don't know how to fix. i need to somehow have a counter, but it needs to be "saved". i thought that using application("counter")=application("counter") + 1 would do it, but it is cleared every time. i need to be able to increase the counter in some code and somehow save it, then with the links part, have maybe a for loop after i opened up the database, see if the "PostNum" = I (loop var) and then display some fields as a link. when i add new data to the db, i want something like:
    : : [code]
    : : Application("counter") = Application("counter") + 1 'or something
    : : 'like that since that didn't seem to work.
    : : adoRs.Fields("PostNum") = counter 'i know how to do the db stuff,
    : : 'but not having a counter that will save each time that code is run.
    : : [/code]
    : : Then in a different page create links with certain fields.
    : :
    :
    : [hr][grey]To err is human, but to really foul things up requires a computer. (Farmers Almanac)[/grey] :-)
    :
    :

    [hr][grey]To err is human, but to really foul things up requires a computer. (Farmers Almanac)[/grey] :-)

  • : ok... one more correction:
    :
    : Response.Write doesn't take parentheses, so it looks like:
    :
    : : Response.write "Login"

    ok thanks, that might be my problem with the response.write but i dont get an error either...
  • : let me restart my problem lol. i found some other problems that i don't know how to fix. i need to somehow have a counter, but it needs to be "saved". i thought that using application("counter")=application("counter") + 1 would do it, but it is cleared every time. i need to be able to increase the counter in some code and somehow save it, then with the links part, have maybe a for loop after i opened up the database, see if the "PostNum" = I (loop var) and then display some fields as a link. when i add new data to the db, i want something like:
    : [code]
    : Application("counter") = Application("counter") + 1 'or something
    : 'like that since that didn't seem to work.
    : adoRs.Fields("PostNum") = counter 'i know how to do the db stuff,
    : 'but not having a counter that will save each time that code is run.
    : [/code]
    : Then in a different page create links with certain fields.
    :


    [code]
    'you have to intially set the value of Application("counter") =0
    'somewhere in your application.It is usually done in Application_on_Start in the global.asa file and thissub is called when
    'the application is first started , or when the first asp page from your site is called.
    Application.Lock 'to prevent simultaneous updation
    Application("counter") = Application("counter") + 1 'Must work
    Appliation.Unlock

    adoRs.Fields("PostNum") = Application("counter")
    [/code]

  • : [code]
    : 'you have to intially set the value of Application("counter") =0
    : 'somewhere in your application.It is usually done in Application_on_Start in the global.asa file and thissub is called when
    : 'the application is first started , or when the first asp page from your site is called.
    : Application.Lock 'to prevent simultaneous updation
    : Application("counter") = Application("counter") + 1 'Must work
    : Appliation.Unlock
    :
    : adoRs.Fields("PostNum") = Application("counter")
    : [/code]
    :
    i already have all that, my code just doesn't write the links.

  • i finally got everything to work! it had to do with my counter. instead of using application, i pulled out the Fields("PostNum") and added 1, then when i wrote the new post to the db i used that. thanks for your guy's help.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories