Grabbibg the net record

Results 1 to 2 of 2

Thread: Grabbibg the net record

  1. #1
    Join Date
    Dec 1969

    Default Grabbibg the net record

    I have a page where I build a thumbnail of many images. The user can decide how they want to sort these, By date, name, topic, etc. Once a user clicks on a thumbnail it displays that thumbnail on a new page. So now they are seeing a bigger version of the image and all the tetual information regarding it from the DB. I want to allow them to jump to the next record without having to go back to the thumbnail page every time. A simple "Next&#062;&#062;" link.<BR><BR>My database&#039;s PM is an autonumber and it has some gaps from deleted records. So I can&#039;t just grab the next ID not to mention that sometimes I will be building the thumbnail list osrted bu other criteria... so simply getting the next ID is not a solution.<BR><BR>What would be the best way to get the next record? I don&#039;t want to retrieve all the records everytime, then just choose the first. When a user clicks on a thumbnail, I do something like:<BR>&#039;---------------------------------------------------------------<BR>StrSql = " " &_<BR>"SELECT * " &_<BR>"FROM TABLE1, TABLE2 " &_<BR>"WHERE TABLE1.ID=" & Request.QueryString("Id") &_<BR>"AND TABLE2.CatId = TABLE1.CatId "<BR>&#039;---------------------------------------------------------------<BR>so this returns the single record so that I can build the "detail" page, but if I want to also build a link to the next available record.... well, I don;t know. I can&#039;t get my head around it. Everything that comes to mind involves a TON of code and has to be the wrong way. This seems like something that people must do often.<BR><BR>Has anyone done this? Any ideas?<BR><BR>Thanks!<BR>Steve Klett<BR><BR>PS: If you would like to see this in operation, check it out:<BR> click on the browse trucks option<BR><BR>I display a single record on a page, there are many records in my database. My Primary key is out of sequence and has gaps(missing sections) from deleting records, etc.<BR>I need to be able to display the next available record in mt database, 1 at a time. I can&#039;t rely on the PK because sometimes I will display them in all different orders.

  2. #2
    Join Date
    Dec 1969

    Default A sneaky trick...

    On the current page, let&#039;s say you have this:<BR><BR>&#060;IMG Src="ford713.jpg"&#062;<BR>&#060;FORM&#062;<BR>&#0 60;INPUT Type=Hidden Name="Order" Value="DatePosted"&#062;<BR>&#060;INPUT Type=Hidden Name="Current" Value="#3/15/2001#"&#062;<BR>&#060;INPUT Type=Submit Value="Next"&#062;<BR>&#060;/FORM&#062;<BR><BR>Now, that submits you right back to the current page! Where you do this:<BR><BR>&#060;%<BR>order = Request("Order")<BR>current = Request("Current")<BR>SQL = "SELECT TOP 1 * FROM table " _<BR>&nbsp; &nbsp; &nbsp; & "WHERE " & order & " &#062; " & current & " ORDER BY " & order<BR>... make connection ...<BR>Set RS = conn.Execute( SQL )<BR><BR>&#039; change current<BR>current = RS( order ) <BR>Select Case VarType( current )<BR>&nbsp; &nbsp; Case vbDate<BR>&nbsp; &nbsp; &nbsp; &nbsp; current = "#" & current & "#"<BR>&nbsp; &nbsp; Case vbString<BR>&nbsp; &nbsp; &nbsp; &nbsp; current = "&#039;" & current & "&#039;"<BR>End Select<BR>%&#062;<BR>&#060;FORM&#062;<BR>&#060;INP UT Type=Hidden Name="Order" Value="&#060;% = order %&#062;"&#062;<BR>&#060;INPUT Type=Hidden Name="Current" Value="&#060;% = current %&#062;"&#062;<BR>&#060;INPUT Type=Submit Value="Next"&#062;<BR>&#060;/FORM&#062;<BR><BR>***********************<BR><BR>D oes it make sense? Each time you hit next, you are asking for the first record that has an "order" field with a value greater than the "current" value!<BR><BR>If the field type is a Date or String we wrap it in the delimiters needed by the DB. (Remember, only Access uses #..#, all other DBs use &#039;...&#039;)<BR><BR>To get it all started, post to this same page with the appropriate "order" value and a zero or zero-equivalent "current" value.<BR><BR>NOTE: This does *not* handle ties! The second and subsequent record with the same value as the current one will be skipped. If that&#039;s a problem, first get this up and working with that boo-boo and then post code and I can show you how to fix it.<BR><BR>(Oh heck... to fix, just add the ID field to the WHERE and ORDER BY clauses! And change &#062; to &#062;= for the original WHERE. So your SQL query becomes something like:<BR>&nbsp; &nbsp; SELECT TOP 1 * FROM table <BR>&nbsp; &nbsp; WHERE TruckName &#062;= &#039;ford732&#039; AND ID &#062; 7732 <BR>&nbsp; &nbsp; ORDER BY TruckName, ID<BR><BR>Does it make sense?)<BR><BR>

Posting Permissions

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