I am working on a photo gallery. in php. the code so far is thus:
Code:<?php
//Connect to Database
include("userDbConnection.php");
// select pictures from database
$pictureQuery="Select * from gallery";
$runPictureQuery=mysql_query($pictureQuery)or die("An Error has occured. We apologise for any inconveniance. <br /> <br /> The Following error has occured:<br />" . mysql_error());
//set i to zero use to make array item
$i=0;
//read pictures into an array
while($getPictures=mysql_fetch_array($runPictureQuery))
{
$description[$i] = $getPictures['g_description'];
$pic[$i] = $getPictures['g_pic'];
$i++;
}
//set j to 0. this will be used to refrence the pictures in the pic array
$j=0;
//display the image
echo "<center><br /><img src='gallery/" . $pic[$j] . "' border=0 /></center><br />";
//display the description
echo "<center>" . $description[$j] . "</center><br />";
?>
I have not really ever done javascript before which is what i think is needed for this next part. I basically just want a button that says next that will increase $j by 1 and reload the picture and the description with the new value. any help would be appreciated
It's actually not javascript, but ajax. That's what you need. So just read simple ajax tutorial here: Using POST method in XMLHTTPRequest(Ajax) and I think you'll be able to do your work and if not, ask, I'll try to help.
hmmm. maybe. Thou correct me if I am wrong isn't Ajax used to retrieve information from the server? My script already has the data and I just want to go to the next value in the array that has already been made. (also note that ajax is javascript. not that it matters for our discussion)
But your array is in your php and won't be sent to the page so the JavaScript can't access it. But maybe your Javascript could set the image source to "/yourphppage.php?image=" + (imagenumber + 1), and then your php page is checking the GET input image and loads the image so the JavaScript could get it. But otherwise you would probably need ajax.
ok. I think i will look into getting javascript to open a directory and read all the file names from it so i can display pics that way.
Thanks guys
to do that, you need an xml or json to read the information from...
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
i don't know but i found this which is working great: Dynamically populating a JavaScript image slideshow
But didn't you want the images from a database?
yes, but only so it could have a description with it. I don't mind giving the description the axe
I tried it fast and come up with this: http://vswe.codecall.net/Image%20Browser/
It is storing the images in a database, if you want to use a data base I could give you the code which you can modify to make it better. Or you can jsut stick with the one you have![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks