Navigate in database

Discussion in 'ASP General' started by Vinnie Davidson, Mar 24, 2005.

  1. Hi!

    I have a detail page that shows one spesific record based on the article ID.
    I need to make a navigation on this detail page, with "previous article" and
    "next article" links.
    So, my question is how can I get the previous and next article ID based on
    the article that is open??

    I though about the MovePrevious and MoveNext methods, but it was no
    success...
    The SQL needs some parameters to get the correct records, like the example
    below with "artID", "catID", "active", "custID".
    My thoughs here is to open the record I'm in, move to previos record and get
    the ID, move to next 2 times to get the next ID... Ofcouse this dont work
    becouse of the artID in the SQL....?


    <%
    varID = Request.QueryString("id")

    SQL = "SELECT artID, catID, active, custID from tblArticle where " &_
    "((artID = '"&varID&"') AND (custID = '3') AND (active = '1'))"

    set rsNavigate = server.CreateObject("adodb.recordset")
    rsNavigate.Open SQL,connstring

    rsNavigate.MovePrevious
    dbPrev = rsNavigate.Fields("artID") 'Hoped this would give me the
    previous ID..

    rsNavigate.MoveNext
    rsNavigate.MoveNext
    dbNext = rsNavigate.Fields("artID") 'Hoped this would give me the next
    ID...

    rsNavigate.Close
    set rsNavigate = nothing
    %>


    Can anyone please help me???
    Vinnie :)
     
    Vinnie Davidson, Mar 24, 2005
    #1
    1. Advertising

  2. Vinnie Davidson

    Steven Burn Guest

    If IsValidID(Clng(varID -1)) Then lPrevID=Clng(varID -1) Else lPrevID="NULL"
    If IsValidID(Clng(varID +1)) Then lNextID=Clng(varID +1) Else lNextID="NULL"

    Obviously you'll want to check to make sure the ID is valid before printing it to the page (did this on my freeware site).

    Although I'm probably going to get crucified for doing it this way, I've used the following (modified a bit as I doubt you'll be using the fields I am).... works just fine for me;

    <%
    Function IsValidID(sID)
    '// Allow numeric sID's only
    If IsNumeric(sID)=False Then IsValidID=False: Exit Function

    '// DB Connection etc goes here
    objRst.Open "Select fldID From tblTable_Name order by fldID ASC", objDB, adOpenStatic, adLockReadOnly
    Do While not fRst.eof
    If objRst("fldID") = sID Then
    IsValidID = True
    Exit Do
    End If
    fRst.MoveNext
    Loop
    objRst.Close
    End Function
    %>

    --
    Regards

    Steven Burn
    Ur I.T. Mate Group
    www.it-mate.co.uk

    Keeping it FREE!

    "Vinnie Davidson" <> wrote in message news:uyGS#...
    > Hi!
    >
    > I have a detail page that shows one spesific record based on the article ID.
    > I need to make a navigation on this detail page, with "previous article" and
    > "next article" links.
    > So, my question is how can I get the previous and next article ID based on
    > the article that is open??
    >
    > I though about the MovePrevious and MoveNext methods, but it was no
    > success...
    > The SQL needs some parameters to get the correct records, like the example
    > below with "artID", "catID", "active", "custID".
    > My thoughs here is to open the record I'm in, move to previos record and get
    > the ID, move to next 2 times to get the next ID... Ofcouse this dont work
    > becouse of the artID in the SQL....?
    >
    >
    > <%
    > varID = Request.QueryString("id")
    >
    > SQL = "SELECT artID, catID, active, custID from tblArticle where " &_
    > "((artID = '"&varID&"') AND (custID = '3') AND (active = '1'))"
    >
    > set rsNavigate = server.CreateObject("adodb.recordset")
    > rsNavigate.Open SQL,connstring
    >
    > rsNavigate.MovePrevious
    > dbPrev = rsNavigate.Fields("artID") 'Hoped this would give me the
    > previous ID..
    >
    > rsNavigate.MoveNext
    > rsNavigate.MoveNext
    > dbNext = rsNavigate.Fields("artID") 'Hoped this would give me the next
    > ID...
    >
    > rsNavigate.Close
    > set rsNavigate = nothing
    > %>
    >
    >
    > Can anyone please help me???
    > Vinnie :)
    >
    >
     
    Steven Burn, Mar 24, 2005
    #2
    1. Advertising

  3. Thanks for your answer!

    If I understand this right, the code just add or remove 1 from the current
    ID (varID). This would work fine if i knew that the previous og next ID is
    the one I want, but I dont. I have to check if the previous or next ID has
    the correct categoryID (catID), customerID (custID) and active = 1. If these
    criteria dont match, the code should "jump" to next record .... think you
    got the point.. :)

    This is a "nut"for me....



    "Steven Burn" <> wrote in message
    news:%...
    If IsValidID(Clng(varID -1)) Then lPrevID=Clng(varID -1) Else lPrevID="NULL"
    If IsValidID(Clng(varID +1)) Then lNextID=Clng(varID +1) Else lNextID="NULL"

    Obviously you'll want to check to make sure the ID is valid before printing
    it to the page (did this on my freeware site).

    Although I'm probably going to get crucified for doing it this way, I've
    used the following (modified a bit as I doubt you'll be using the fields I
    am).... works just fine for me;

    <%
    Function IsValidID(sID)
    '// Allow numeric sID's only
    If IsNumeric(sID)=False Then IsValidID=False: Exit Function

    '// DB Connection etc goes here
    objRst.Open "Select fldID From tblTable_Name order by fldID ASC",
    objDB, adOpenStatic, adLockReadOnly
    Do While not fRst.eof
    If objRst("fldID") = sID Then
    IsValidID = True
    Exit Do
    End If
    fRst.MoveNext
    Loop
    objRst.Close
    End Function
    %>

    --
    Regards

    Steven Burn
    Ur I.T. Mate Group
    www.it-mate.co.uk

    Keeping it FREE!

    "Vinnie Davidson" <> wrote in message
    news:uyGS#...
    > Hi!
    >
    > I have a detail page that shows one spesific record based on the article
    > ID.
    > I need to make a navigation on this detail page, with "previous article"
    > and
    > "next article" links.
    > So, my question is how can I get the previous and next article ID based on
    > the article that is open??
    >
    > I though about the MovePrevious and MoveNext methods, but it was no
    > success...
    > The SQL needs some parameters to get the correct records, like the example
    > below with "artID", "catID", "active", "custID".
    > My thoughs here is to open the record I'm in, move to previos record and
    > get
    > the ID, move to next 2 times to get the next ID... Ofcouse this dont work
    > becouse of the artID in the SQL....?
    >
    >
    > <%
    > varID = Request.QueryString("id")
    >
    > SQL = "SELECT artID, catID, active, custID from tblArticle where " &_
    > "((artID = '"&varID&"') AND (custID = '3') AND (active = '1'))"
    >
    > set rsNavigate = server.CreateObject("adodb.recordset")
    > rsNavigate.Open SQL,connstring
    >
    > rsNavigate.MovePrevious
    > dbPrev = rsNavigate.Fields("artID") 'Hoped this would give me the
    > previous ID..
    >
    > rsNavigate.MoveNext
    > rsNavigate.MoveNext
    > dbNext = rsNavigate.Fields("artID") 'Hoped this would give me the
    > next
    > ID...
    >
    > rsNavigate.Close
    > set rsNavigate = nothing
    > %>
    >
    >
    > Can anyone please help me???
    > Vinnie :)
    >
    >
     
    Vinnie Davidson, Mar 24, 2005
    #3
  4. Vinnie Davidson

    Jeff Cochran Guest

    On Thu, 24 Mar 2005 12:35:45 +0100, "Vinnie Davidson"
    <> wrote:

    >Thanks for your answer!
    >
    >If I understand this right, the code just add or remove 1 from the current
    >ID (varID). This would work fine if i knew that the previous og next ID is
    >the one I want, but I dont. I have to check if the previous or next ID has
    >the correct categoryID (catID), customerID (custID) and active = 1. If these
    >criteria dont match, the code should "jump" to next record .... think you
    >got the point.. :)
    >
    >This is a "nut"for me....


    In otherwords your ID isn't sequential, and you're just querying data
    for the ID in question, correct? Might want to pull in all matching
    records and then use recordset paging to accomplish your task. Take a
    look at:

    http://www.aspfaq.com/show.asp?id=2120

    Jeff


    >"Steven Burn" <> wrote in message
    >news:%...
    >If IsValidID(Clng(varID -1)) Then lPrevID=Clng(varID -1) Else lPrevID="NULL"
    >If IsValidID(Clng(varID +1)) Then lNextID=Clng(varID +1) Else lNextID="NULL"
    >
    >Obviously you'll want to check to make sure the ID is valid before printing
    >it to the page (did this on my freeware site).
    >
    >Although I'm probably going to get crucified for doing it this way, I've
    >used the following (modified a bit as I doubt you'll be using the fields I
    >am).... works just fine for me;
    >
    ><%
    > Function IsValidID(sID)
    > '// Allow numeric sID's only
    > If IsNumeric(sID)=False Then IsValidID=False: Exit Function
    >
    > '// DB Connection etc goes here
    > objRst.Open "Select fldID From tblTable_Name order by fldID ASC",
    >objDB, adOpenStatic, adLockReadOnly
    > Do While not fRst.eof
    > If objRst("fldID") = sID Then
    > IsValidID = True
    > Exit Do
    > End If
    > fRst.MoveNext
    > Loop
    > objRst.Close
    > End Function
    >%>
     
    Jeff Cochran, Mar 24, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Fitzpatrick
    Replies:
    0
    Views:
    1,778
    Mark Fitzpatrick
    Jun 25, 2003
  2. Sean
    Replies:
    1
    Views:
    525
    S. Justin Gengo
    Jul 31, 2003
  3. Guogang

    caveat using smart navigate?

    Guogang, Aug 30, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    383
    szabelin
    Aug 30, 2003
  4. Bill Cohagan

    How best to "navigate" (newbie)

    Bill Cohagan, Nov 14, 2003, in forum: ASP .Net
    Replies:
    6
    Views:
    412
    -=Chris=-
    Nov 16, 2003
  5. cs_in_va

    Navigate to URLs within the database

    cs_in_va, Jan 22, 2008, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    100
    PJ on Development
    Jan 23, 2008
Loading...

Share This Page