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 -
-
<%
-
'declare your variables
-
'declare SQL statement that will query your database
-
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"
-
'create ADO connection and recordset object
-
Set connection = Server.CreateObject("ADODB.Connection")
-
Set recordset = Server.CreateObject("ADODB.Recordset")
-
'define the connection string, specify database
-
'driver and the location of database
-
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
-
"Data Source=" & Server.MapPath("/fpdb/greetingcardpro.mdb")
-
'Open the connection to the database
-
connection.Open(sConnString)
-
'Open the recordset object executing the SQL
-
recordset.Open sql, connection, 3, 1
-
'count the number of records and hold this is the variable intTotalRecords
-
intTotalRecords = recordset.RecordCount
-
Randomize()
-
intRandomNumber = Int(intTotalRecords * Rnd)
-
'move to the random number returned
-
recordset.Move intRandomNumber
-
'open the table
-
'loop through the total number of fields
-
For i = 0 to recordset.Fields.Count - 1
-
'write out the field value
-
Response.write("<a href="""" title="" ""><img width=""100%"" class=""bord"" alt="" "" src=""" & recordset(i) & """/></a>")
-
Next
-
'close the recordset and connection objects and free up resources
-
recordset.Close
-
Set recordset=Nothing
-
connection.close
-
Set connection=Nothing
-
%>
-
3 3585
fran7, without digging in to deep something caught my eye. Look at one of the loops you are doing. -
-
'loop through the total number of fields
-
For i = 0 to recordset.Fields.Count - 1
-
'write out the field value
-
Response.write ("<a href="""" title="" ""><img width=""100%"" class=""bord"" alt="" "" src=""" & recordset (i) & """/></a>")
-
Next
-
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.
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): -
-
<%
-
'declare your variables
-
'declare SQL statement that will query your database
-
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"
-
Jared
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
%>
Sign in to post your reply or Sign up for a free account.
Similar topics |
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:
|
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...
|
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
|
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:
|
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
*/
| |
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?
|
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
|
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
|
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.
|
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,...
|
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...
| |
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |