I have an array in javascript that holds the images stored in the db, and the script works for the most part since the images show up. But the problem is there are separate arrays created for each image and I want them to be in the same array. I cant figure out how to write the for loop so the array declaration is not apart of the for loop.
Heres the page that shows what Im talking about.
http://tweakurpages.com/test.php
This is where the problem is Im pretty sure:
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$id = $row['id'];
$t = $row['title'];
for ($i = 0; $i <= $num_pics; $i++) {
echo '<script type="text/javascript">';
echo 'var images=new Array()
images[' . $i . ']=["modules/pic.php?id=' . $id . '", "' . $t . '", "modules/show_pic.php?id=' . $id . '", "300px"]
';
echo 'var thepics=new photogallery(images, 3, 2, "500px", "600px", ["Browse Images:", "Page"])';
echo '</script>';
} //end for loop
} //end while
Here is the whole code incase that helps:
// Count the number of records
$query = "SELECT COUNT(*) FROM images ORDER BY id DESC";
$result = @mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_NUM);
$num_pics = $row[0];
$query = "SELECT id, title, name FROM images ORDER BY id DESC";
$result = @mysql_query ($query); // Run the query.
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$id = $row['id'];
$t = $row['title'];
for ($i = 0; $i <= $num_pics; $i++) {
echo '<script type="text/javascript">';
//Define your own array to hold the photo album images
//Syntax: ["path_to_thumbnail", "opt_image_title", "opt_destinationurl", "opt_linktarget"]
echo 'var images=new Array()
images[' . $i . ']=["modules/pic.php?id=' . $id . '", "' . $t . '", "modules/show_pic.php?id=' . $id . '", "300px"]
';
//initiate a photo gallery
//Syntax: new photogallery(imagearray, cols, rows, tablewidth, tableheight, opt_[paginatetext_prefix, paginatetext_linkprefix])
echo 'var thepics=new photogallery(images, 3, 2, "500px", "600px", ["Browse Images:", "Page"])';
echo '</script>';
}
} //end while
} // end IF