473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

asp random image plus alt description

229 100+
Hi, I have this nice code that returns a random image database record. It works great. What I am trying to do now is to be able to get the "alt" description for the image from another field. If I add another field to the query it returns two images. I was making the alt alt=""" & recordset(i) & """ but I know that must be wrong. well it works but returns the image name, ie images/friday.jpg. Anyone know how I can get it to return the image description from another field related to the image randomly returned. Thanks for any help.
Richard

Expand|Select|Wrap|Line Numbers
  1.  
  2. <% 
  3. 'declare your variables
  4. 'declare SQL statement that will query your database
  5. sql = "Select thumbnailurl FROM tblGreetPost Where CategoryID <> " & 60 & " and CategoryID <> " & 63 & " and CategoryID <> " & 61 & " and CategoryID <> " & 64 & " and CategoryID <> " & 66 & " and CategoryID <> " & 65 & " ORDER BY dateadded asc"
  6. 'create ADO connection and recordset object
  7. Set connection = Server.CreateObject("ADODB.Connection")
  8. Set recordset = Server.CreateObject("ADODB.Recordset") 
  9. 'define the connection string, specify database
  10. 'driver and the location of database
  11. sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _ 
  12. "Data Source=" & Server.MapPath("/fpdb/greetingcardpro.mdb") 
  13. 'Open the connection to the database
  14. connection.Open(sConnString)
  15. 'Open the recordset object executing the SQL 
  16. recordset.Open sql, connection, 3, 1
  17. 'count the number of records and hold this is the variable intTotalRecords
  18. intTotalRecords = recordset.RecordCount
  19. Randomize()
  20. intRandomNumber = Int(intTotalRecords * Rnd)
  21. 'move to the random number returned
  22. recordset.Move intRandomNumber
  23. 'open the table
  24. 'loop through the total number of fields
  25. For i = 0 to recordset.Fields.Count - 1
  26. 'write out the field value
  27. Response.write("<a href="""" title="" ""><img width=""100%"" class=""bord"" alt="" "" src=""" & recordset(i) & """/></a>")
  28. Next
  29. 'close the recordset and connection objects and free up resources
  30. recordset.Close
  31. Set recordset=Nothing
  32. connection.close
  33. Set connection=Nothing
  34. %>
  35.  
Jan 22 '09 #1
3 3569
stepterr
157 100+
fran7, without digging in to deep something caught my eye. Look at one of the loops you are doing.

Expand|Select|Wrap|Line Numbers
  1.  
  2. 'loop through the total number of fields 
  3. For i = 0 to recordset.Fields.Count - 1 
  4.  'write out the field value 
  5.  Response.write ("<a href="""" title="" ""><img width=""100%"" class=""bord"" alt="" "" src=""" & recordset (i) & """/></a>") 
  6. Next 
  7.  
It looks like you are looping through each field, but yet in your query you only select one field from the table. I would start there.
Jan 22 '09 #2
jhardman
3,406 Expert 2GB
Richard,

stepterr is right, you are currently only asking the db to give you one field of data. You will need to select two fields (something like this):
Expand|Select|Wrap|Line Numbers
  1.  
  2. <% 
  3. 'declare your variables
  4. 'declare SQL statement that will query your database
  5. sql = "Select thumbnailurl, thumbnaildescription FROM tblGreetPost Where CategoryID <> " & 60 & " and CategoryID <> " & 63 & " and CategoryID <> " & 61 & " and CategoryID <> " & 64 & " and CategoryID <> " & 66 & " and CategoryID <> " & 65 & " ORDER BY dateadded asc"
  6.  
Jared
Jan 22 '09 #3
fran7
229 100+
Thanks guys, Yes that was the problem but I eventually got it going like this.
Thanks Richard


<%
' ADO Constant. Dont change this
' Connection string and SQL statement
Dim sql , connStr
sql = "Select author,artist,tip,website,thumbnailurl,postcardid, download FROM tblGreeting Where CategoryID <> " & 60 & " and CategoryID <> " & 63 & " and CategoryID <> " & 61 & " and CategoryID <> " & 64 & " and CategoryID <> " & 66 & " and CategoryID <> " & 65 & " ORDER BY dateadded asc"
connStr = " Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("/fpdb/data.mdb" )
' Opening database
Dim rs
Set rs = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql, connStr, 3, , adCmdText
' Generating random number from total number of records
Dim intRnd
Randomize Timer
intRnd = (Int(RND * rs.RecordCount))
' Now moving the cursor to random record number
rs.Move intRnd
' Showing the random statement
Response.Write " <a target=""_blank"" href=""http://""><img width=""100%"" alt=""" & rs("download") & """ border=""0"" src=""" & rs("thumbnailurl") & """></a><br><br>"
' Closing the database
rs.Close
Set rs = Nothing
%>
Jan 23 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Ken | last post by:
How does IE6 control the display of images? I change the content of a image file image1.jpg without changing the file name. Then jump to a new page to display it. IE6 does not displays the...
3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
2
by: George | last post by:
Hi, The code below comes directly from http://www.dynamicdrive.com. It does exactly half of what I'd like it to do. The other half is this: I'd like the image block of the changing images to...
2
by: Jim in Arizona | last post by:
I was trying to create a random image generator. I'm using visual web dev express with 2.0 framework. On the web form page (mypage.aspx), I have an image control: <asp:Image ID="Image1"...
6
by: comp.lang.php | last post by:
/** * Generate the random security image * * @access public * @param $willUseFilePath (default false) boolean to determine if you will be using a file path * @param mixed $filePath (optional)...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
4
by: Kim | last post by:
Random image downloader for specified newsgroup. Hi I'm writing a small script that will download random images from a specified newsgroup. I've imported yenc into the script but I can't open the...
12
by: skip | last post by:
Is there a module out there that will generate an image with a random text string such as the confirmation images you see on various websites? I'm thinking I'm going to have to add that to the...
5
by: Michael | last post by:
Hello all, how could I rotate a server side image in asp.net and show it in web page? Thanks.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.