Print Page | Close Window

Displaying Pictures from Database

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=4763
Printed Date: 30 March 2026 at 1:12pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Displaying Pictures from Database
Posted By: Misty
Subject: Displaying Pictures from Database
Date Posted: 05 August 2003 at 10:56am

I have a products catalog. I would like to be able to display the pictures from a database on a web page. I already know how to do this. However, I would like to be able to display two pictures on the same line. If it happens that there are 5 pictures to show. I would like for the last one to show up without giving me an error message. How would I do this?

Please take a look at http://www.signaturecarpets.com/runninglines.php?type=Cut+Pile - http://www.signaturecarpets.com/runninglines.php?type=Cut+Pile  to get an idea what I am talking about.




Replies:
Posted By: Mart
Date Posted: 05 August 2003 at 10:59am
It works fine for me, no errors...


Posted By: Misty
Date Posted: 05 August 2003 at 11:01am

Mart,

That web page doesn't belong to me. I was just using that page as an example. I would like to be able to do something like that in ASP. Does anyone know how to do this in ASP?

 



Posted By: ljamal
Date Posted: 05 August 2003 at 11:15am
If you are using a recordset(rs)
<table>
<%
cnt=1
Do while not rs.EOF
if cnt mod 2 = 1 then Response.Write "<tr>" end if
Response.Write "<td>Stuff goes here</td>"
cnt=cnt+1
if cnt mod 2 = 1 then Response.Write "</tr>" end if
rs.MoveNext
Loop
if cnt mod 2 = 0 then Response.Write "</tr>" end idf
%>
</table>

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: Flamewave
Date Posted: 05 August 2003 at 11:48am

The gallery that I created should be of some help, download the code and take a peek, then you can see how to do it, or just use it.

http://www.flameservers.com/asp_apps/gallery/ - www.flameservers.com/asp_apps/gallery/

Hope this helps.



-------------
- Flamewave

They say the grass is greener on the other side, but if you really think about it, the grass is greener on both sides.


Posted By: Misty
Date Posted: 05 August 2003 at 1:32pm

Flamewave, Thank you for your willingness to share your code!

I have the web page up at http://65.174.82.72/specials2.asp - http://65.174.82.72/specials2.asp . There is an error message on this web page. I only want two pictures to show up on one line. I suspect that the error message is due to me having a third picture. I will copy and paste my code for you. Does anyone know how to this code to make the error message disappear? Please look at the error message on the page. The third picture showed up, but the product's name didn't show up.

Take a look at my code below.

dim rs

dim sqlString

dim connectionString, databaseName, path

dim SpecialsID, ImageName, SpecialsName

'Set connection details (No need to include the code for this)

Const NUM_COLUMNS = 2

Dim EndOfRS

Dim NumRecords, Temp1, Temp2, Temp3, i

EndOfRS = 0

NumRecords = 0

 

'Start sql string with Join

sqlString = "select * from Specials"

'Create a recordset

set rs = Server.CreateObject("ADODB.Recordset")

rs.CursorType = 2

rs.Open sqlString, connectionString

%>

<HTML>

<HEAD>

<TITLE>Specials</TITLE>

<p>

<P>

</HEAD><BODY>

<center><table border="0" width="100%">

<%

Do While Not rs.EOF

NumRecords = NumRecords + 1

rs.MoveNext

Loop

rs.MoveFirst

Do While NOT rs.EOF %>

<tr>

<%

For i=1 to NUM_COLUMNS

%><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="ViewSpecial.asp?qryID=<%=rs("SpecialsID")%>"><img src=../Upload/<%= rs("ImageName") %> width="144" height="144" border="0" alt=<%= rs("SpecialsName")%>></a></td>

<% If rs.EOF Then

EndOfRS = 1

Exit For

End If

rs.MoveNext

Next

If EndOfRS = 0 Then

rs.Move -NUM_COLUMNS

If rs.BOF = True Then

rs.MoveFirst

End If

End If

If EndOfRS = 1 Then

rs.MoveFirst

Temp1 = InStr((NumRecords / NUM_COLUMNS), ".")

Temp2 = Left((NumRecords / NUM_COLUMNS), Temp1-1)

Temp3 = Temp2 * NUM_COLUMNS

rs.Move Temp3

End If

%>

</tr>

<tr>

<%

For i=1 to NUM_COLUMNS

%><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><%= rs("SpecialsName") %></b><p><p><p></td>

<%rs.MoveNext

If rs.EOF Then Exit For

Next

%>

</tr>

<% Loop %>

</center></table>

</body>

</html>

 



Posted By: Flamewave
Date Posted: 05 August 2003 at 6:12pm

Hehe...it looks like you are using an older ASP gallery that I had developed back when I was first learning ASP. The new one that I posted the link to above is much better and performs a bit faster, and it's easier to customize, just FYI.

As far as the error goes, Try changing the two for...next loops to check for eof before any work is done in the loop:

 For i=1 to NUM_COLUMNS
  If rs.EOF Then
   EndOfRS = 1
   Exit For
  End If
%>
     <td>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <a href="ViewSpecial.asp?qryID=<%=rs("SpecialsID")%>"><img src=../Upload/<%= rs("ImageName") %> width="144" height="144" border="0" alt=<%= rs("SpecialsName")%>></a>
     </td>
<%
  rs.MoveNext
 Next

 For i=1 to NUM_COLUMNS
  If rs.EOF Then Exit For
%>
     <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><%= rs("SpecialsName") %></b><p><p><p></td>
<%
  rs.MoveNext
 Next

Hope that helps.



-------------
- Flamewave

They say the grass is greener on the other side, but if you really think about it, the grass is greener on both sides.


Posted By: Misty
Date Posted: 06 August 2003 at 11:30am

Flamewave, Thank you for the help! You helped me to build a web application for cards before. That is where I got the old code from. The new gallery is good. I just didn't want to have pages numbered.

The error message is gone. However, I don't like the space between the pictures. I wish that the pictures were closer. I removed the spaces before the <td> tag. Does anyone know how I might be able to move the pictures closer to each other. You can take a look at http://65.174.82.72/specials2.asp - http://65.174.82.72/specials2.asp .

 

 



Posted By: KCWebMonkey
Date Posted: 06 August 2003 at 11:42am
The table width is set at 100%. try taking out the table width and then the cells will only be as big as their contents.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net