473,606 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

asp random image plus alt description

229 New Member
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 3585
stepterr
157 New Member
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 Recognized Expert Specialist
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 New Member
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,t ip,website,thum bnailurl,postca rdid,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=Micros oft.Jet.OLEDB.4 .0; Data Source=" & Server.MapPath( "/fpdb/data.mdb" )
' Opening database
Dim rs
Set rs = Server.CreateOb ject("ADODB.Con nection")
Set rs = Server.CreateOb ject("ADODB.Rec ordset")
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("thumbnailur l") & """></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
3549
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 original picture, not the new image. If I press F5, the correct image is displayed. I tried:
3
11752
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 table in MySQL with the path & filename to the image. I have successfully uploaded and performed an update query on the database, but the problem I have is I cannot retain the primary key field in a variable which is then used in a SQL update...
2
1724
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 move up and down, as the user scrolls up and down on the page. Can any of you folks suggest how I would envelope the following code
2
2885
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" runat="server" /> On the codebehind, (mypage.aspx.vb), I have this code when a button is clicked:
6
3067
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) file path to store image resource object contents * @see actual_path */
4
2743
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. It should put a blue and yellow box on the page with "This is a test" as part of the picture. But what I get is a broken Gif. The other problem is that I can't view the source???? The view source is disabled for this page. What causes this?
4
3072
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 image or save it. This is my first script so be gentle! Heres the script ####random group downloader#### import nntplib import string, random import mimetools import StringIO
12
2791
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 forms on the Mojam websites. Over the past couple weeks we've begun to get lots of spam submission crap. Thx, Skip
5
3441
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
7951
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8439
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8430
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
5465
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3930
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2448
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1553
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1296
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.