View Full Version : Image Thumbnail Viewer II load from database

05-09-2006, 09:13 AM
Script: Image Thumbnail Viewer II
Link: http://www.dynamicdrive.com/dynamicindex4/thumbnail2.htm

Hey everyone, I can't figure out how to set the image in the array to be retrieved from the database, is there any way I can do that? I managed to be able to get the thumbnails from my database, but for example...

var dynimages=new Array()
dynimages[0]=["image1.jpg", ""]
dynimages[1]=["image2.jpg", ""]
dynimages[2]=["image3.jpg", ""]

I want to be able to get that value dynamically, i'm still learning javascript and asp.net so sorry if its a simple question, Thanks in advance!

p.s. I like the fading effect :)

05-09-2006, 07:46 PM
You can't do it with Javascript. However...

Client side coding like javascript can't connect to a serverside database. You need serverside code/scripting.

I don't like ASP, so here's an example in php... use asp if you so desire.

Just an example, so won't fit exactly what you are doing, but it's a good start.

var dynimages=new Array()
<?php //connect to database here
$query = mysql_query("SELECT `URL` FROM `images`");
while ($row = mysql_row_assoc($query)) {
echo 'dynimages['.$n.']=["'.$row['URL'].'", \"\"]';
?>That will print a link of terms with increasing $n values for dynimages[0], dynimages[1], etc. with the URL from the database (table "images") as the url of the image.

Make sense?

05-09-2006, 08:43 PM
Thanks djr33, looks easier in php than it would be in .net, I think I understand how to do it in .net, not just to figure out how to put it in code :), thanks!

05-10-2006, 05:19 PM
Good. There's more info at php.net on connecting to the database, etc.

Perhaps you can use what you're used to but with the setup I have above. Not sure if it applies.

good luck :)