I have some images in the table images
, the fields are id
, name
and photo
. Where the image exists in photo
.
At the minute, the code below not getting any images, although there should be about 4 images that match the query. The images that meet the query should go into the slideshowimages("")
variable.
<?php
// Connect to the database
require('mysqli.php');
// Query for a list of all existing files
$sql = "SELECT * FROM images WHERE name= '$pagetitle'";
$result = $conn->query($sql);
$directory = '';
while( $image = $result->fetch_assoc() )
$directory .= ($directory != '' ? "," : '') . ('"/images/'.$image["photo"] . '"');
// Check if it was successfull
if($image) {
// if there are images for this page, run the javascript
?><script>
//configure the paths of the images, plus corresponding target links
//NEED TO GET ALL RELEVANT IMAGE LOCATIONS INTO LINE BELOW
slideshowimages("<?php echo $directory ?>")
//configure the speed of the slideshow, in miliseconds
var slideshowspeed=2000
var whichlink=0
var whichimage=0
function slideit(){
if (!document.images)
return
document.images.slide.src=slideimages[whichimage].src
whichlink=whichimage
if (whichimage<slideimages.length-1)
whichimage++
else
whichimage=0
setTimeout("slideit()",slideshowspeed)
}
slideit()
</script> <?php
} else {
// If there are not any images for this page, leave the space blank
echo "";
}
// Close the mysql connection
$conn->close();
?>
The JavaScript that is in the head
<script language="JavaScript1.1">
var slideimages=new Array()
var slidelinks=new Array()
function slideshowimages(){
for (i=0;i<slideshowimages.arguments.length;i++){
slideimages[i]=new Image()
slideimages[i].src=slideshowimages.arguments[i]
}
}
</script>