1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

adding code on page to html that comes from a database..

Discussion in 'C#' started by red_fiesta, Nov 8, 2006.

  1. #1
    i have html that is stored in a database for one part of a site..

    so when <%=rsText("text")%> is written it writes to screen the html

    when there is links in this html they show fine but i want to add something to the link... ie ?id=1

    is there a way of doing this? I want to do it in the asp page as this will be used as a template and the id will change

    so to clarify one part of the html stored in the database may have..

    <a href="/content/test/File/red/Pontus/test.asp">test</a>

    which will show test as a link
    SEMrush
    but i want to add in ?id=1 but not to the database code...

    please help

    thanks
     
    red_fiesta, Nov 8, 2006 IP
    SEMrush
  2. Froggie

    Froggie Well-Known Member

    Messages:
    665
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    120
    #2
    make a function in asp that will add ur numbers and call it from asp

    so you could have <%=MyFunc(rsText("text"))%>

    and my func would be like this

    sub myFunc(str)
    myFunc = str & "1"
    end Sub
     
    Froggie, Nov 8, 2006 IP
  3. DangerMouse

    DangerMouse Peon

    Messages:
    275
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    So, you've written the whole anchor into the database? Hmmm... That make it a little harder to work with... It would make more sense (to me!) if you stored the file name in the DB as it would be easier to manipulate the link this way...

    This will work though: <%= Replace(rsText("text"), ".asp", ".asp?id=1") %>
     
    DangerMouse, Nov 8, 2006 IP
  4. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i think you missed the point..

    for example rsText("text") could be

    <p>  The products we are importing are red, white and sparkling wines. We do also import cognacs, grappas and local spirits. Today we have partnerships with award winning wineyards located in Spain, Italy, France and Greece.  </p>
    <p>   For more information, please <a target="_parent" href="../info/">contact us</a>.</p>
    Code (markup):
    I only need to add the ?id=1 to the ahref so it would be ../info/?id=1

    make more sense?
     
    red_fiesta, Nov 8, 2006 IP
  5. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I explain with an example

    i have three sites say

    roger
    sam
    paul

    roger has a siteid of 1, sam a siteid of 2 and paul of 3

    and within the text stored in the database thier maybe three links

    strText = "Hello there, please visit <a href=""/sites/roger/about/about.asp"">roger about</a> or <a href=""/sites/paul/products.asp"">sam product</a> or <a href=""http://www.jacintotrading.com"">jacintotrading</a> "


    the first link will need a ?id=1 the second will need a ?id=3 and the last no ?id

    does this make sense?
     
    red_fiesta, Nov 8, 2006 IP
  6. DangerMouse

    DangerMouse Peon

    Messages:
    275
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #6
    This will still work: <%= Replace(rsText("text"), """>", "?id=1"">") %>

    Edit - sorry, now it won't

    You could split the string on say, "</a>" giving you:

    array(0) "Hello there, please visit <a href=""/sites/roger/about/about.asp"">roger about"
    array(1) "or <a href=""/sites/paul/products.asp"">sam product"
    array(2) "or <a href=""http://www.jacintotrading.com"">jacintotrading"
    array(3) ""

    Then loop through your new array and update each part:

    For x = 0 to Ubound(array)

    If array(x) <> "" Then
    newstr = newstr & Replace(rsText("text"), """>", "?id=" & (x+1) & """>") & "</a> "
    End If

    Next
     
    DangerMouse, Nov 8, 2006 IP
  7. DangerMouse

    DangerMouse Peon

    Messages:
    275
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #7
    this assumes you want to count them of course...
     
    DangerMouse, Nov 8, 2006 IP
  8. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    ok, i am going to change the way i do it....

    i am going to add the id before i post to the database..

    so i need now to get the request.form item

    so

    <%=request.form("postedTextFromEditor")%>

    which returns

    <p> <a href="/cm/website/File/roger/test.asp">he</a>is a young innovative man. </p>
    <p>Today we have partnerships with award winning wineyards located in Spain, Italy, France and Greece. </p> <p> For more information, please <a href="/cm/website/File/maincontact/contact.asp" target="_parent">contact us</a>.</p>

    i will now need to somehow return the words roger and maincontact so that i can find the site ids for them

    then will need to add a ?siteid='number' to here

    so that when the link is stored its stored with correct id

    a count wont work as id needs to come from db..
     
    red_fiesta, Nov 8, 2006 IP
  9. N_F_S

    N_F_S Active Member

    Messages:
    2,475
    Likes Received:
    56
    Best Answers:
    0
    Trophy Points:
    90
    #9
    You can find words roger and maincontact if you find the location of first occurance of "/" after the word File & the location of "/" afterwards. I've done it before by stripping the string, however here it's not needed believe me, I think you are doing something the hard way.......try redesigning your db structure instead of creating functions when you can live without them (in this case I believe).
     
    N_F_S, Nov 8, 2006 IP
  10. Garve

    Garve Peon

    Messages:
    62
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I think I agree with NFS - you're not going to find a simple solution to this, and it would be much better not to have to pass the querystring such as id=1

    Why do you need it? Why doesn't the page '/cm/website/File/roger/test.asp' know that it is number 1 without needing to be told by a querystring?
     
    Garve, Nov 8, 2006 IP
  11. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    it needs that id=1 or what ever cause this is the site id

    and this is the main table in the database

    ie i use two or three templates and when a page is created it is copied and renamed to the location of the site files.

    there is a dbcall at the top of the page that asks for the site id so that it can get the data
     
    red_fiesta, Nov 9, 2006 IP