9 Replies - 7497 Views - Last Post: 14 September 2006 - 03:10 AM Rate Topic: -----

#1 absta  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 13-April 06

Random image display query

Posted 30 August 2006 - 02:38 PM

Guys any ideas where i'm missing the point here still getting my head around this ASP lark

I want to bring back the entire product list, check how many records there were and use this as a basis for a random number then filter to that record. Any comments most appreciated, thanks.

Quote

<%
Dim random, imgRS, intRecordCount
Set imgRS = Server.CreateObject("ADODB.Recordset")
randomize
random = int((50) * rnd + 100)
mySQL = "SELECT * FROM tblProducts"
imgRS.Open mySQL, imgRS, adOpenDynamic, adLockOptimistic, adCmdText

For intRecordCount = imgRS.RecordCount To random
imgRS.Filter = "lngProductID"
If Not imgRS.EOF Then
Response.Write"<table><tr><td><b>Best Sellers</b></td></tr>"
While Not myRS.EOF
Response.Write"<td>" & imgRS("strImage") & "</td>"
imgRS.MoveNext
Wend
Response.Write"</table>"
End If
Next

imgRS.Close
SetimgRS = Nothing
%>


Is This A Good Question/Topic? 0
  • +

Replies To: Random image display query

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Random image display query

Posted 30 August 2006 - 04:17 PM

Assuming that rnd is a call to the function as opposed to a variable that is not declared in the given code, it should be Rnd().

Check the example of a random number generator here:
http://www.asp101.co...%5Fnumber%2Easp
Was This Post Helpful? 0
  • +
  • -

#3 absta  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 13-April 06

Re: Random image display query

Posted 31 August 2006 - 02:44 AM

me thinks my code is sh*te i'll have another go tonight and let you know how I get on
Was This Post Helpful? 0
  • +
  • -

#4 absta  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 13-April 06

Re: Random image display query

Posted 02 September 2006 - 07:55 AM

ok guys i've got this but the pics are displaying above my homepage, i using a 3 col layout and I'd like the 2 or 3 pics to show in the centre column under some existing text. Any advice appreciated, thanks.

Quote

<%
randomize
Dim random, imgRS, RecordCount, random_number

Set imgRS = Server.CreateObject("ADODB.Recordset")
random_number = int (rnd*1)+1
imgRS.Open "tblProducts", strConnect, adOpenKeyset, adLockReadOnly, adCmdTable
RecordCount = imgRS.RecordCount

If Not imgRS.EOF Then
Response.Write "No records found"
End If
If imgRS("strImage") <> "" Then
Response.Write "<p>" & imgRS.Filter = "lngProductID=" & random_number & """</p>"
End If
While Not imgRS.EOF
Response.Write "<div><img src=""site_images/" & imgRS("strImage") & """ alt=""""></div>"
imgRS.Move 1
Wend


imgRS.Close
Set imgRS = Nothing
%>

Was This Post Helpful? 0
  • +
  • -

#5 absta  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 13-April 06

Re: Random image display query

Posted 04 September 2006 - 02:34 PM

any advice would be better than nothing ... but hey ho
Was This Post Helpful? 0
  • +
  • -

#6 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Random image display query

Posted 04 September 2006 - 04:17 PM

Alright...can you provide a little more of the code? You mention a three column layout. How is that being accomplished? In a table? Without a table? Do you want the 2 or three pics to be in the same column? You mention you want them under text...do you mean that you want them so that the text appears to be over (higher on the page) the pics, or you want the text to be sumperimposed on the pics?
Was This Post Helpful? 0
  • +
  • -

#7 absta  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 13-April 06

Re: Random image display query

Posted 06 September 2006 - 12:33 PM

Hi Amadeus right the 3 column layout is being accomplished using css - I've already got an index page set up with includes and a bit of text
<%@ Language=VBScript
EnableSessionState = True%>
<%Option Explicit%>
<!-- #INCLUDE FILE = "adovbs.asp" -->
<!-- #INCLUDE FILE = "dbconx.asp" -->
<!-- #INCLUDE FILE = "preheader.asp" -->
<title>For all the Fragrances you'll need! from LifestyleFragrances.co.uk</title>
<!-- #INCLUDE FILE = "header.asp" -->
<h2>Welcome to Lifestyle Fragrances</h2>
<hr>
<p>We've got some excellent bargains running currently.  Please browse through our categories to find out what 
we can offer you ! Call us on <strong>0845 905 0906</strong> to order by phone.</p>
<hr><p>The best place to shop for women's fragrance and men's aftershave.  Because we're an online store, we don't have 
the same overheads as high street shops, so we can offer our customers designer fragrance and aftershave products at 
discount prices. Take your time to look through our wide selection of quality womens perfume and our aftershave range.
Enjoy!</p>
<p>Here's a selection of our best sellers:</p>
<!-- #INCLUDE FILE = "rotate.asp" -->
<!-- #INCLUDE FILE = "footer.asp"-->


The rotate.asp code is bringing back all of the images and I'm a bit stuck as I only want 4 or a couple i was going to use floating divs to lay them out under the text

<% 

Dim imgRS, RecordCount, random_number												
Set imgRS = Server.CreateObject("ADODB.Recordset")	randomize
random_number = int (rnd * RecordCount)+1						 								
imgRS.Open "tblProducts", strConnect, adOpenDynamic, adLockOptimistic, adCmdTable   ' open it
RecordCount = imgRS.RecordCount 

If imgRS.EOF Then
Response.Write "<p>" & imgRS.Filter = "lngProductID=" & random_number & """</p>"
End If
While Not imgRS.EOF
Response.Write "<p><img src=""site_images/" & imgRS("strImage") & """ alt=""""></p>"
imgRS.Move 1
Wend	

imgRS.Close
Set imgRS = Nothing
%>


hope I'm not boring you to death ..... cheers
Was This Post Helpful? 0
  • +
  • -

#8 absta  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 13-April 06

Re: Random image display query

Posted 07 September 2006 - 10:43 AM

Solution at last this is the code that generates random images x3 underneath the existing text on my Welcome page, it's an include in index.asp

<p style="text-align: center"><!-- #INCLUDE FILE = "rotate.asp" --></p>


<% 

Dim imgRS, RecordCount, random_number, FeaturedProduct												

Set imgRS = Server.CreateObject("ADODB.Recordset")					
randomize
			 								

imgRS.Open "tblProducts", strConnect, adOpenStatic, adLockReadOnly, adCmdTable   
RecordCount = imgRS.RecordCount 

For FeaturedProduct = 1 to 3
Do
random_number = int (rnd * RecordCount)		

imgRS.Move random_number,1
Loop Until Not imgRS.EOF

Response.Write "<a href=""products.asp?ProductID=" & imgRS("lngProductID") & """><img src=""site_images/" & imgRS("strImage") & """ alt="""" border=""0"" height=""100""></a>"

Next


imgRS.Close
Set imgRS = Nothing
%>


HOORAY really pleased at last got some products displaying on the homepage plus I sorted out a Recordset paging problem in the category display page now on to the next task !

This post has been edited by absta: 07 September 2006 - 10:45 AM

Was This Post Helpful? 0
  • +
  • -

#9 absta  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 13-April 06

Re: Random image display query

Posted 08 September 2006 - 01:54 AM

Response.Write "<a href=""products.asp?ProductID=" & imgRS("lngProductID") & """><img src=""site_images/" & imgRS("strImage") & """ alt="""" border=""0"" height=""100""></a>"


Hey would like the alt attribute to state the image name - do i add in imgRS("strImage") in here ???

<img src=""site_images/" & imgRS("strImage") & imgRS("strImage") & """ alt="""" border=""0"" height=""100""></a>


cheers
Was This Post Helpful? 0
  • +
  • -

#10 absta  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 13-April 06

Re: Random image display query

Posted 14 September 2006 - 03:10 AM

ok it was a case of adding this to the alt attribute

alt='"&imgRS("strTitle")&"'

alt text looking good ...... pesky syntax ....... :rolleyes:

This post has been edited by absta: 14 September 2006 - 03:13 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1