Hi people.
This is the website http://www.creativestar.co.nz/clients/amber/
I am creating a website for a friend it is in its early stages so none of the buttons work and the colors are a bit off but, i thought it would be cool to have this "quick view" feature where people could cycle through a few pictures and click on them to go to a page including more information.
My PHP knowledge is still at the PHP for dummies stage, but this is what I want hope somebody can help.
Every time the page loads in the quick view there is 1 random image showing from about 10 different images. If someone is interested they click on the image and it goes to a different page bypassing the gallery page.
The arrows will have to load the previous|next picture and cycle through the 10 different pictures without having to refresh the page.
Is this difficult ?
Thanks
I want to cycle some images... Any help would be great
Moderator: General Moderators
-
Cloud_Battery
- Forum Newbie
- Posts: 3
- Joined: Wed Sep 24, 2008 12:59 am
Re: I want to cycle some images... Any help would be great
I think this is not the PHP related stuff.
For this, better to use Adobe Flash.
For this, better to use Adobe Flash.
-
Cloud_Battery
- Forum Newbie
- Posts: 3
- Joined: Wed Sep 24, 2008 12:59 am
Re: I want to cycle some images... Any help would be great
I could... But i am looking for alternatives that don't require a plug in.
Is this not possible in PHP ?
Is this not possible in PHP ?
Re: I want to cycle some images... Any help would be great
PHP won't do that directly - if you don't want the page to reload you need to use client-side scripting such as javascript rather than server-side scripting such as php. There are millions of tutorials and examples of how to change images using javascript - google will point you in the right direction.
-
Darkzaelus
- Forum Commoner
- Posts: 94
- Joined: Tue Sep 09, 2008 7:02 am
Re: I want to cycle some images... Any help would be great
It is possible. First you would need to get an array of filenames, which can be gotten with this handy piece of code: http://www.phpjabbers.com/ask91-read-fi ... g-php.html.
Then you will need to generate a random number between 0 and the size of the said array -1. Then, set the variable holding the image path as the index of the array, which is generated by the random number. I use mt_rand() as it faster than rand(), but both do the same job.
This will select a random image when loaded. Then yes, you will need javascript to go through the images.
Cheers,
Darkzaelus
Then you will need to generate a random number between 0 and the size of the said array -1. Then, set the variable holding the image path as the index of the array, which is generated by the random number. I use mt_rand() as it faster than rand(), but both do the same job.
Code: Select all
$image_file_path = '/home/user/www/path/'; - this is the full server path to your images folder
$d = dir($image_file_path) or die("Wrong path: $image_file_path");
while (false !== ($entry = $d->read())) {
if($entry != '.' && $entry != '..' && !is_dir($dir.$entry))
$Images[] = $entry;
}
$d->close();
$random=mt_rand(0,sizeof($Images)-1);
$image_path=$Images[$random];
Cheers,
Darkzaelus
-
Cloud_Battery
- Forum Newbie
- Posts: 3
- Joined: Wed Sep 24, 2008 12:59 am
Re: I want to cycle some images... Any help would be great
I managed to get this far using the code you gave me and inserting where i want the picture.
http://www.creativestar.co.nz/clients/amber/index.php
What would I add to the buttons to make it scroll to the previous|next pic without them being random ?
Thanks
Code: Select all
<img src="images/cycle/<?php echo $image_path ?>" alt="" />http://www.creativestar.co.nz/clients/amber/index.php
What would I add to the buttons to make it scroll to the previous|next pic without them being random ?
Thanks
-
Darkzaelus
- Forum Commoner
- Posts: 94
- Joined: Tue Sep 09, 2008 7:02 am
Re: I want to cycle some images... Any help would be great
Create a hidden field that holds the index of the current image. You will need to create a javscript array holding all the filenames, and then when you click on each button, increment the index counter, and change the source of the image tag:
Hope this helps.
Cheers,
Darkzaelus.
Code: Select all
<img src="images/cycle/TestA.jpg" alt="" /> //TO::
<img src="images/cycle/TestA.jpg" alt="" id="img"/>
Cheers,
Darkzaelus.