PDA

View Full Version : data driven image grid


robocop
07-29-2003, 09:00 PM
Hey there to you all...i have a simple, yet complex question to rack your minds :)

i have a page that has a product on it, but that product has like 30 patterns, and more could be added/deleted/modified later. so im instantly thinkin that ill need to set up a database like this:

+----+-------------------+-----------------------+----------+
+ ID | ItemName | ImgLocation | Active |
+----+-------------------+-----------------------+----------+
+ 1 | FlamePattern | /images/fire.jpg | Yes |
+ 2 | WaterPattern | /images/water.gif | No |
+----+-------------------+-----------------------+----------+

then, i want to make a popup window that basically writes out the images of the ACTIVE items to the page so that the customer can click on them to select the pattern instead of looking at a 303 item drop down menu. im thinkin that ill just have a javaScript function set up to just fill in a form field with the "ItemName" variable...

now...is this even possible? and if so...does anyone know off the top of their head what the code woudl look like? im new to ASP (usually develop in ColdFusion)....and we have to work on an ASP server for this one.......

i thank you all so much in advance!

kc

oracleguy
07-29-2003, 10:13 PM
<%
Dim Conn, rs
Set Conn=Server.CreateObject("ADODB.Connection")

Conn.Open "<YOUR DATABASE CONNECTION INFO"

Set rs=Server.CreateObject("ADODB.RecordSet")
rs.Open "SELECT * FROM products WHERE active=1;", conn

Do While NOT rs.EOF

%>
<p>
<a href="order.asp?Item=<%= rs.Fields("ItemName").Value %>">
<img src="<%= rs.Fields("ImgLocation").Value %>" alt="<%= rs.Fields("ItemName").Value %>" />
</a>
</p>
<%

rs.MoveNext
Loop

rs.Close
Set rs=Nothing

Conn.Close
Set Conn = Nothing
%>

You'll need to insert your database connection info and possible change the table name. But it should work.

You can change the html it uses to display the images and stuff as you see fit.

robocop
07-29-2003, 10:16 PM
Hello God.....thank you for blessing me with this wonderful code...i just dug up some tutorials and was learning this on my own....this was pretty much what i was planning....damn man...thanks!

kc

photoman
07-29-2003, 10:22 PM
my code was bad please ignor and look at oracleguys code

oracleguy
07-29-2003, 11:11 PM
No problem. :thumbsup:

robocop
07-30-2003, 03:05 AM
ok...i tried this, but i ran into a snag.....how would i populate a 2- column, multi-row table with this code?

right now, its placing duplicates in each row....how would i go about placing a seperate image in the right and left hand columns?

thanks for the help yall.

kc

oracleguy
07-30-2003, 04:44 AM
<%
Dim Conn, rs
Set Conn=Server.CreateObject("ADODB.Connection")

Conn.Open "<YOUR DATABASE CONNECTION INFO"

Set rs=Server.CreateObject("ADODB.RecordSet")
rs.Open "SELECT * FROM products WHERE active=1;", conn

%>
<table>
<% Do While NOT rs.EOF %>
<tr>
<td>
<a href="order.asp?Item=<%= rs.Fields("ItemName").Value %>">
<img src="<%= rs.Fields("ImgLocation").Value %>" alt="<%= rs.Fields("ItemName").Value %>" />
</a>
</td>
<% rs.MoveNext %>
<% If rs.EOF Then Exit Do %>
<td>
<a href="order.asp?Item=<%= rs.Fields("ItemName").Value %>">
<img src="<%= rs.Fields("ImgLocation").Value %>" alt="<%= rs.Fields("ItemName").Value %>" />
</a>
</td>
</tr>
<%
rs.MoveNext
Loop
%>
</table>
<%
rs.Close
Set rs=Nothing

Conn.Close
Set Conn = Nothing
%>

Okay. It was a simple fix. And I added a check to make sure it doesn't error out if there is an uneven number of pictures.

robocop
07-30-2003, 03:37 PM
this is very cool man, thanks to you, i feel now that i have a grasp on the whole DB / ASP thing....thank you very much.

so if i wanted to make these in a popup window -- and then have the ability to click on one of the images and have that click fill in a form field on the window that spawned the popup, would i just give the parent window a name and then reference that in the onClick event?

how exactly would i refer to that other window?

oracleguy
07-30-2003, 09:08 PM
My pleasure.

You know, I've seen it done. You can do it with a little javascript. Your best bet would be to try searching first in the Javascript Programming forum. If you can't find anything, make a new thread about it and one of javascript gurus will help ya out.