Help - Search - Members - Calendar
Full Version: Arrow Navigation
Zymic Webmaster Forums > Web Design & Development > General Web Design Discussion
weasleysww
I'm really kind of stupid at when it comes to web design, so I have a question:

I want to make a thing where it allows someone to navigate through images of varying sizes from a list (assuming php), without the user having to reload the entire page, with a Next/Previous Last/First Navigation. Looking like this

----------------------------
----------------------------
----------------------------
----------------------------
----------IMAGE----------
----------------------------
----------------------------
----------------------------
<Last Next>
First Last
Andrew
Without reloading the page would be done with ajax or javascript of some sort.
weasleysww
i don't know either js or ajax. Can someone please help?
weasleysww
Please help!
Jetteh22
Or you could put the image and the first next last etc in an iframe. Easier, but probably won't be as good looking, and a pain in the ass if the images are in different sizes.
weasleysww
but that way I have to make an HTML page for each image, someone else will be updating it weekly with a new image and I want it to be easy as possible for them.
k.digennaro
Check out light box, it does that. Very easy to install and use!
http://www.huddletogether.com/projects/lightbox2/


Also for the easy updating you could check out http://www.cushycms.com/. This would allow you to update the images easily and allow others to update them as well. My suggestion would be to use light and cushy together.

Kevin DiGennaro
weasleysww
since i won't be using it I need something that doesn't require a download, and I don't need a popup, just the image and Next/prev/last buttons/links
Jetteh22
DONE!
I've done it for you!
It took me 2 hours as I am not good w/ javascript but i've finished it!

http://www.thinkcreactive.com/testingimage.php is a demo...
At the top of the page i put all the images so you can be sure that they are going in the correct order. At bottom it tells you the total # of images.

Here is the code.
I am -assuming- you know PHP and Javascript (at least a little) and you'll be able to break it down. I didn't bother coding it or anything but I can garauntee it's my work.

What you need to do is create a mysql database and then a table in it w/ 2 rows (id and one called urls) - have your friend add all of the URLS to the images to that database (or create an upload form that will do it automatically) and then voila! It's all done...

No refreshes or anything, javascript does it without refreshes.. Here you go.
If you have any questions on the code, let me know lol.

CODE
<?php
mysql_connect("localhost","MYSQLUSERNAME","MYSQLPASSWORD") or die(mysql_error());
mysql_select_db("IMAGEDATABASE") or die(mysql_error());
$sql = "SELECT * from images";
$result = mysql_query($sql);

$totalimages = 0;
$imageurls = array("null");
?>
<script language="javascript">
<!--
var imageurls = new Array();
imageurls[0] = "null";
-->
</script>

<?php
while($row = mysql_fetch_array($result)) {
array_push($imageurls,$row['url']);
$totalimages +=1;
echo ?>
<script language="javascript">
<!--
imageurls.push("<?php echo $row['url'];?>");
-->
</script>
<img src="<?php echo $row['url'];?>">
<?php

}
?><center><br><br><br><br>

<a href="#" onclick="goFirst()">First</a> |
<a href="#" onclick="goPrev()">Prev</a> |
<a href="#" onclick="goNext()">Next</a> |
<a href="#" onclick="goLast()">Last</a>

<br>
<img src="<?php echo $imageurls[1];?>" id="im">
</center>
<br><br>
<?php echo $totalimages;?><br>


<script type="text/javascript">
<!--
var totalimages = <?php echo $totalimages; ?>;
var currentimage = 1;
var nextimage;
var previmage;

function goFirst() {
currentimage = 1;
document.getElementById('im').src='<?php echo $imageurls[1];?>';
}

function goLast() {
currentimage = totalimages;
document.getElementById('im').src='<?php echo $imageurls[$totalimages];?>';
}

function goNext() {
if((currentimage + 1) > totalimages)
{
currentimage = totalimages - 1;
}
document.getElementById('im').src=imageurls[currentimage+1];
currentimage += 1;
}

function goPrev() {
if((currentimage - 1) < 1)
{
currentimage = 2;
}
document.getElementById('im').src=imageurls[currentimage-1];
currentimage -= 1;
}

-->
</script>


EDIT: If anyone wants to clean up the code and make it look better and still work and comment it, ect, feel free to do so. Just don't name it as your own work as this did take me a while to do. I'm always up for a challenge.
weasleysww
I'll show it to the person I'm searching for, thank you!
Jetteh22
No problem, hope it helped.
Now that I've actually done that I might go more in depth and create a nice image gallery script.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.