Databases, arrays, and random links...

Results 1 to 2 of 2

Thread: Databases, arrays, and random links...

  1. #1
    Join Date
    Dec 1969

    Default Databases, arrays, and random links...

    Hi,<BR>I&#039;ve made a map that highlights different regions as you move your mouse over it. I&#039;ve set it so that depending on which region you click on, a different variable ("Sitelist") is sent to a second page, which controls which monitoring sites are shown (i.e. Click on the western region, only sites within the western region are shown on the next page). Another variable (siteinfo) is also sent to the 2nd page, which determines which site&#039;s data will be shown. The link is like so: <BR> 0Harbor&Sitelist=11<BR><BR>My problem is that I have had to hard code in a specific site so that the SQL statements on the second page have all the necessary variables. What I want to have happen is that instead of a hardcoded default site, the user is directed to a random site from within the selected region. For example, if sites 2, 7, 9, 15 and 34 are all within the western region, then when you click on the western region, you pass either 2, 7, 9, 15 or 34 to the next page.<BR><BR>I thought this could be done by creating an array for each region, then having the link pick one of the values at random from the appropriate array. The problem is that I don&#039;t know where to start.<BR><BR>To get an idea of what I&#039;m talking about, please check out<BR><BR>Thanks,<BR>Mike

  2. #2
    Join Date
    Dec 1969

    Default You're 90% of the way there

    Unless one or more of these regions has many, many sites (say more than 100???), then I&#039;d just build your SQL to get *all* sites from the clicked-on region.<BR><BR>Then take that recordset and read it into an array using GETROWS.<BR><BR>Then pick a random row from the array.<BR><BR>&#060;%<BR>SQL = "SELECT siteID, siteName FROM sites WHERE regionID = " & Request("Region")<BR>Set RS = yourConnection.Execute( SQL )<BR>sites = RS.GetRows( )<BR>RS.Close<BR>Randomize<BR>row = INT( RND * ( UBound(sites,2)+1 ) )<BR>Response.Write "Site id is " & sites(0,row) & ", site name is " & sites(1,row) & "&#060;P&#062;"<BR>...<BR>%&#062;<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