I have a record in an access dbase that has some stuff in it
and then on a web page I have this code.
<% If cstr(rsProducts("Logos")) = "OP" Then %>
<img name="Logo" src="images/op_big.gif" alt="Out of Print">
<% End If %>
<% If cstr(rsProducts("Logos")) = "NLT" Then %>
<img name="NLT" src="images/NLTlogo.gif" alt="New Living Translation">
<% End If %>
<% If cstr(rsProducts("Logos")) = "LBk" Then %>
<img name="Lbk" src="images/LBklogo.gif" alt="Living Books">
<% End If %>
<% If cstr(rsProducts("Logos")) = "GM" Then %>
<img name="Logo" src="images/GMlogo.gif" alt="Gold Medallion Award>
<% End If %>
This works, however, if the field has more then one answer it wont work.
(the page still works, but it wont display any logos)
If there is more then one logo, it would be separated in the field by a
comma
so sometimes there are a combination of logos for each one, and I want to
display the appropriate logos for each product
NLT, LbK, GM etc.
is there an operator I can use so if it the record contains such and such
instead of = 11 3241
Try this for efficiency!
<%
Do While Not rsProduct.EOF
strItem = Ucase(Trim(rsProducts("Logos")))
If Len(strItem) > 0 Then
aryData = Split(strItem,",")
For intCount = 0 To UBound(aryData)
ReSponse.Write GetImage(aryData(intCount))
Next
End If
rsProduct.MoveNext
Loop
Function GetImage(strLogo)
Select Case UCase(Trim(strLogo))
Case "OP"
strImage = "images/op_big.gif"
strName = "Logo"
strAlt = "Out of Print"
Case "NLT"
strImage = "images/NLTlogo.gif"
strName = "NLT"
strAlt = "New Living Translation"
Case "LBK"
strImage = "images/LBklogo.gif"
strName = "Lbk"
strAlt = "Living Books"
Case "GM"
strImage = "images/GMlogo.gif"
strName = "Logo"
strAlt = "Gold Medallion Award"
Case Else
strImage = ""
strName = ""
strAlt = ""
End Select
If Len(strImage) > 0 Then
Dim ary(6)
ary(0) = "<img name='"
ary(1) = strName
ary(2) = " src='"
ary(3) = strImage
ary(4) = "' alt='"
ary(5) = strAlt
ary(6) = "'>"
GetImage = Join(ary,"")
End If
End Function
%>
-dlbjr
Discerning resolutions for the alms
or using select case...
aryData = Split(strItem,",")
for intCount = 0 to Ubound(aryData)
select case ucase(trim(aryData(intCount)))
case "OP": i = "op_big.gif": n = "Logo": a = "Out of print"
case "NLT": i = "NLTlog.gif": n = "NLT": a = "New Living
Translation"
case.........
case........
end select
if i <> "" then
response.write "<img src='" & i & "' name='" & n & "' alt='" & a &
"'>"
end if
next
On Fri, 19 Sep 2003 18:59:08 -0500, "dlbjr" <do******@do.u> wrote: Try this for efficiency!
<% Do While Not rsProduct.EOF strItem = Ucase(Trim(rsProducts("Logos"))) If Len(strItem) > 0 Then aryData = Split(strItem,",") For intCount = 0 To UBound(aryData) ReSponse.Write GetImage(aryData(intCount)) Next End If rsProduct.MoveNext Loop
Function GetImage(strLogo) Select Case UCase(Trim(strLogo)) Case "OP" strImage = "images/op_big.gif" strName = "Logo" strAlt = "Out of Print" Case "NLT" strImage = "images/NLTlogo.gif" strName = "NLT" strAlt = "New Living Translation" Case "LBK" strImage = "images/LBklogo.gif" strName = "Lbk" strAlt = "Living Books" Case "GM" strImage = "images/GMlogo.gif" strName = "Logo" strAlt = "Gold Medallion Award" Case Else strImage = "" strName = "" strAlt = "" End Select If Len(strImage) > 0 Then Dim ary(6) ary(0) = "<img name='" ary(1) = strName ary(2) = " src='" ary(3) = strImage ary(4) = "' alt='" ary(5) = strAlt ary(6) = "'>" GetImage = Join(ary,"") End If End Function %>
-dlbjr
Discerning resolutions for the alms
wow, you guys totally lost me. I don't know vb at all, just putting together
code based one what I see on the page that dreamweaver generated. Your stuff
looks more complicated then mine and I'm not sure I completely understand
it.
I pasted the code from dlbjr right under my rs query and I get this error
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'rsProduct'
/copy/pdetails.asp, line 26
Secondly, how do I use the function you made?
Just like this
<%= GetImage %> ?
I'd check obviously but I got that error I pasted.
Here's my code, as you can see, line 26 is the beginning of your loop
<!--#include file="Connections/connMain.asp" -->
<%
Dim rsProducts__MMColParam
rsProducts__MMColParam = "1"
If (Request.QueryString("ISBN") <> "") Then
rsProducts__MMColParam = Request.QueryString("ISBN")
End If
%>
<%
Dim rsProducts
Dim rsProducts_numRows
Set rsProducts = Server.CreateObject("ADODB.Recordset")
rsProducts.ActiveConnection = MM_connMain_STRING
rsProducts.Source = "SELECT * FROM Products WHERE ISBN = '" +
Replace(rsProducts__MMColParam, "'", "''") + "'"
rsProducts.CursorType = 0
rsProducts.CursorLocation = 2
rsProducts.LockType = 1
rsProducts.Open()
rsProducts_numRows = 0
%>
<%
Do While Not rsProduct.EOF <-- Line 26
strItem = Ucase(Trim(rsProducts("Logos")))
If Len(strItem) > 0 Then
aryData = Split(strItem,",")
For intCount = 0 To UBound(aryData)
ReSponse.Write GetImage(aryData(intCount))
Next
End If
rsProduct.MoveNext
Loop
Function GetImage(strLogo)
Select Case UCase(Trim(strLogo))
Case "OP"
strImage = "images/op_big.gif"
strName = "Logo"
strAlt = "Out of Print"
Case "NLT"
strImage = "images/NLTlogo.gif"
strName = "NLT"
strAlt = "New Living Translation"
Case "LBK"
strImage = "images/LBklogo.gif"
strName = "Lbk"
strAlt = "Living Books"
Case "GM"
strImage = "images/GMlogo.gif"
strName = "Logo"
strAlt = "Gold Medallion Award"
Case Else
strImage = ""
strName = ""
strAlt = ""
End Select
If Len(strImage) > 0 Then
Dim ary(6)
ary(0) = "<img name='"
ary(1) = strName
ary(2) = " src='"
ary(3) = strImage
ary(4) = "' alt='"
ary(5) = strAlt
ary(6) = "'>"
GetImage = Join(ary,"")
End If
End Function
%>
<!--#include file="Connections/connMain.asp" -->
<%
strMMColParam = "1"
strISBN = Trim(Request.QueryString("ISBN"))
If strISBN <> "" Then
strMMColParam = strISBN
End If
strMMColParam = Replace(strMMColParam, "'", "''")
rs.ActiveConnection = MM_connMain_STRING
strSQL = "SELECT LOGOS, ISBN FROM PRODUCTS WHERE ISBN = '" & strMMColParam &
"'"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = 2
rs.Open strSQL,MM_connMain_STRING,MM_connMain_STRING,0,1
Do While Not rs.EOF
strItem = Ucase(Trim(rs("Logos")))
If Len(strItem) > 0 Then
aryData = Split(strItem,",")
For intCount = 0 To UBound(aryData)
ReSponse.Write GetImage(aryData(intCount))
Next
End If
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Function GetImage(strLogo)
Select Case UCase(Trim(strLogo))
Case "OP"
strImage = "images/op_big.gif"
strName = "Logo"
strAlt = "Out of Print"
Case "NLT"
strImage = "images/NLTlogo.gif"
strName = "NLT"
strAlt = "New Living Translation"
Case "LBK"
strImage = "images/LBklogo.gif"
strName = "Lbk"
strAlt = "Living Books"
Case "GM"
strImage = "images/GMlogo.gif"
strName = "Logo"
strAlt = "Gold Medallion Award"
Case Else
strImage = ""
strName = ""
strAlt = ""
End Select
If Len(strImage) > 0 Then
Dim ary(6)
ary(0) = "<img name='"
ary(1) = strName
ary(2) = " src='"
ary(3) = strImage
ary(4) = "' alt='"
ary(5) = strAlt
ary(6) = "'>"
GetImage = Join(ary,"")
End If
End Function
%>
--
-dlbjr
Discerning resolutions for the alms
<!--#include file="Connections/connMain.asp" -->
<%
strMMColParam = "1"
strISBN = Trim(Request.QueryString("ISBN"))
If strISBN <> "" Then
strMMColParam = strISBN
End If
strMMColParam = Replace(strMMColParam, "'", "''")
strSQL = "SELECT LOGOS, ISBN FROM PRODUCTS WHERE ISBN = '" & strMMColParam &
"'"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = 2
rs.Open strSQL,MM_connMain_STRING,MM_connMain_STRING,0,1
Do While Not rs.EOF
strItem = Ucase(Trim(rs("Logos")))
If Len(strItem) > 0 Then
aryData = Split(strItem,",")
For intCount = 0 To UBound(aryData)
ReSponse.Write GetImage(aryData(intCount))
Next
End If
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Function GetImage(strLogo)
Select Case UCase(Trim(strLogo))
Case "OP"
strImage = "images/op_big.gif"
strName = "Logo"
strAlt = "Out of Print"
Case "NLT"
strImage = "images/NLTlogo.gif"
strName = "NLT"
strAlt = "New Living Translation"
Case "LBK"
strImage = "images/LBklogo.gif"
strName = "Lbk"
strAlt = "Living Books"
Case "GM"
strImage = "images/GMlogo.gif"
strName = "Logo"
strAlt = "Gold Medallion Award"
Case Else
strImage = ""
strName = ""
strAlt = ""
End Select
If Len(strImage) > 0 Then
Dim ary(6)
ary(0) = "<img name='"
ary(1) = strName
ary(2) = " src='"
ary(3) = strImage
ary(4) = "' alt='"
ary(5) = strAlt
ary(6) = "'>"
GetImage = Join(ary,"")
End If
End Function
%>
-dlbjr
Discerning resolutions for the alms
-dlbjr
Discerning resolutions for the alms
> <% If cstr(rsProducts("Logos")) = "OP" Then %> <img name="Logo" src="images/op_big.gif" alt="Out of Print">
Why not store the path information for the logo along with the data in the
database, rather than having to modify the ASP page every time the path
changes, or a product's logo(s) change?
If there is more then one logo, it would be separated in the field by a comma
Well, if this is a many-to-one relationship, you need to alter your design.
Let's say your current table looks like this:
CREATE TABLE Products
(
ProductID INT,
...other stuff...,
Logos VARCHAR(3)
)
Instead, you could do this:
CREATE TABLE Products
(
ProductID INT,
...other stuff...
)
CREATE TABLE ProductLogos
(
ProductID INT,
LogoID INT
)
CREATE TABLE Logos
(
LogoID INT,
imagePath VARCHAR(255)
)
Then your query would be:
SELECT
p.ProductID, l.imagePath
FROM Products p
LEFT OUTER JOIN ProductLogos pl
ON p.ProductID = pl.productID
LEFT OUTER JOIN Logos l
ON pl.logoID = l.logoID
And your ASP code would be:
<%
set rs = conn.execute(query)
cProductID = 0
do while not rs.eof
if rs(0) <> cProductID
' new product
cProductID = rs(0)
response.write cProductID & "<p>"
else
' same product, second logo
response.write "<img src='images/" & rs(1) & "'>"
end if
rs.movenext
loop
%>
Isn't that easier than hard-coding a bunch of if/else or select case logic
into your ASP?
Let me revise the ASP code a bit.
<%
set rs = conn.execute(query)
cProductID = 0
do while not rs.eof
if rs(0) <> cProductID
' new product
cProductID = rs(0)
response.write cProductID & "<p>"
if not isnull(rs(1)) then
response.write "<img src='images/" & rs(1) & "'>"
end if
else
' same product, second logo
response.write "<img src='images/" & rs(1) & "'>"
end if
rs.movenext
loop
%>
dlbjr
On your most recent suggestion, it errored on the sql query so I changed it
to this...
strSQL = "SELECT * FROM Products WHERE ISBN = '" + Replace(strMMColParam,
"'", "''") + "'"
and then after that it errors on Line35
rs.Open strSQL,MM_connMain_STRING,MM_connMain_STRING,0,1
Aaron, I didn't make the dbase, it's something I'm supplied with so I need
to leave it as is, or else updates will be a PIA
The cell that contains the information about logos doesn't relate to
anything else, and it would be a bigger hassle to try and do that
(especially since I have to rely on the publisher for a new dbase with
updates every month) rs.Open strSQL,MM_connMain_STRING,MM_connMain_STRING,0,1
I tried removing the second MM_connMain_STRING and then after that, it
errored on Line 131 which is where I try to call the GetImage function
<%= GetImage %>
so, I guess I just didn't do it right.
Okay, well I finallly got the function call line right
<%= GetImage(strLogo) %>
But when I load the page, it doesn't work unfortunately.
Instead of it displaying any images, it doesn't.
But there is a broken image on the top left of the page for the nlt logo set
to a strange width (140x30) if you right click/properties on the image,
there is no info about the image except the dimensions and if yo uview the
source of the page
<img name='NLT src='images/NLTlogo.gif' alt='New Living Translation'>
this code is placed at the very top, before the html tags. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mark |
last post by:
I have a working PHP/MySQL application used for data entry. The data
entry screen includes a "Save" button. The PHP code for this button
looks like this:
if (isset($_POST))
{
if ($_POST ==...
|
by: yvan |
last post by:
Approximately once a month, a client of ours sends us a bunch of
comma-delimited text files which I have to clean up and then import
into their MS SQL database. All last week, I was using a Cold...
|
by: Arnold |
last post by:
Hi there,
I have a form to organize bottles in mind, but am unsure if it will
work. Here's some background info:
Mainform = frmProduct, which contains fields for pricing, status, etc.
of...
|
by: Steve |
last post by:
I have a form with about 25 fields. In the BeforeUpdate event of the form, I
have code that sets the default value of each field to its current value. For a
new record, I can put the focus in any...
|
by: tdmailbox |
last post by:
I have a form with a child form. In the child form there is a list of
names that can grow quite large. On the parent form I want to display
the first name from the child form. I set up a test...
|
by: Br |
last post by:
First issue:
When using ADPs you no longer have the ability to issue a me.refresh to
save the current record on a form (the me.refresh does a requery in an
ADP).
We usually do this before...
|
by: Andy_Khosravi |
last post by:
I'm having a problem trying to optimize the performance of one of my
A97 databases. I have very slow record navigation after a change I made
to the table structure, and I'm not sure how best to...
|
by: dee |
last post by:
I have a parent form called "FmLeads". It contains a numeric field
called "ID"
It also contains a 3 tab 'Tab Control'.
Each tab contains a subform. One of the subforms
"FmSalesDispositionAll"...
|
by: Swinky |
last post by:
I hope someone can help...I feel like I'm walking in the dark without a
flashlight (I'm NOT a programmer but have been called to task to do
some work in Access that is above my head).
I have...
|
by: samdev |
last post by:
I have a table that contains records that provide the following info:
vehicle type
route #
start time
travel time
end time
I need to display info for all records in a query and/or report...
|
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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: 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...
| |