Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 14th, 2005, 05:11 PM
Authorized User
 
Join Date: Aug 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default recordset not showing up on page loop

Hi,
I have a asp page calling a db and pulling recordsets out and writing them on the homepage randomly. The problem is that some of these recordsets are being deleted. The remaining ones have the ID fields that count 1, 2, 3, 4, 6, 9, 12, and so forth. New ones are also being added. Now the randomizer pulls these out by ID number so if it selects ID 5 then nothing shows on the homepage (because it was deleted), any suggestions on a work around to this issue? Thanks

=================
CODE
=================

<%
    DBOpen()
    ' Get most recent fact sheet
    Set rstemp = conntemp.execute("SELECT * FROM tbl_Client ORDER BY id DESC")
    lowerbound = 1
    upperbound = rstemp("id")
    Randomize
    intRandom = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

    Set rstemp = conntemp.execute("SELECT * FROM tbl_Client WHERE id = " & intRandom)
    If Not rstemp.EOF Then
        rstemp.MoveFirst
        x = 0
        Do Until rstemp.EOF
            If x >= 4 Then
                Exit Do
            End If
            Response.Write "<img border=""0"" src=""../" & rstemp("ImagePath") & """ align=""left"" width=""84"">" & vbCrLf
            Response.Write "" & Mid(TrimHTML(rstemp("Summary")),1,350) & "..." & vbCrLf
            Response.Write "<a href=""clientpage.asp?Client=" & rstemp("id") & """>find out more</a>" & vbCrLf
            x = x + 1
            rstemp.MoveNext
        Loop
    End If
    DBClose()
%>

=============
END of CODE
=============


 
Old December 14th, 2005, 06:43 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Hi Pablo Honey,

If you're using MS-SQL you can write you're select statement pulling the TOP [Integer] and the Newid() function.

Example:

SELECT TOP 10 Clients, Image From tbl_Clients ORDER BY NEWID();

That will pull 10 random clients.

RS






Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop through 17 tables in RecordSet object didimichael C# 1 July 18th, 2008 06:53 AM
Querying Recordset with a Loop rabu Access VBA 10 December 14th, 2005 04:49 PM
Filter recordset in loop Freddyfred Access 1 February 15th, 2005 09:09 AM
Kinda complicated loop through DB Recordset... plasma800 Classic ASP Basics 2 March 4th, 2004 06:23 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.