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 3569
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.
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,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
%>
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...
|
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...
|
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...
|
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"...
|
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)...
|
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.
...
|
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...
|
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...
|
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: 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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
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...
|
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...
|
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,...
| |