ASP VBScript - better way of scripting ...

Please can you let me know if there is a better way of scripting these two conditional statements --

        <td class="img-preview-column">
		<% If Not RsImages.EOF then%>
        <% IF RsImages.Fields.Item("image1") <> "" Then %>
            <img src="<%="http://my.website.com/product-images/"&(RsImages.Fields.Item("image1").Value)%>" />
            <% End If %>
            <%End if%>
            </td>
        <td><input name="image2" type="file" id="image2" value="<% If Not RsImages.EOF then%><% IF RsImages.Fields.Item("image1") <> "" Then %><%=(RsImages.Fields.Item("image1").Value)%><% End If %><%End if%>" /></td>

Open in new window


Many thanks
garethtnashAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pritamduttCommented:
I would suggest you to do something like below

<% If Not RsImages.EOF And RsImages.Fields.Item("image1") <> "" Then
imgFile = RsImages.Fields.Item("image1").Value
End If
%>
<img src="<%=imgFile%>"...

This will help remove the repetitions of the code, and also improve performance by accessing data from variable instead of File.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Wayne BarronAuthor, Web DeveloperCommented:
Get rid of all the unnecessary coding.

 
        <td class="img-preview-column">
		<% If Not RsImages.EOF then
		Image1 = RsImages("image1")%>
        <% IF Image1 <> "" Then %>
            <img src="<%="http://www.mydomain.com/product-images/"&Image1%>" />
            <% End If %>
            <%End if%>
            </td>
        <td><input name="image2" type="file" id="image2" value="<% If Not RsImages.EOF then%><% IF Image1 <> "" Then %><%=Image1%><% End If %><%End if%>" /></td>

Open in new window


Carrzkiss
0
garethtnashAuthor Commented:
Great thank you
0
garethtnashAuthor Commented:
Please can I just quickly check this with you both, based on the above logic, will the following work / is the following the best way of writing --

<%
If Not RsImages.EOF then
Image1 = RsImages("image1")
Image2 = RsImages("image2")
Image3 = RsImages("image3")
Image4 = RsImages("image4")
Image5 = RsImages("image5")

IF Image1 <> "" Then
Session("OLDImage2") = (Image1)
End If

IF Image2 <> "" Then
Session("OLDImage3") = (Image2)
End If

IF Image3 <> "" Then
Session("OLDImage4") = (Image3)
End If

IF Image4 <> "" Then
Session("OLDImage5") = (Image4)
End If

IF Image5 <> "" Then
Session("OLDImage6") = (Image5)
End If
End If
%>

Open in new window


Appreciate your help --

Many thanks
0
garethtnashAuthor Commented:
Got it - thanks

Ignore last post - unless there is a better way -- TY
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.