Hello all,
I have ran into a situation once again: I am writing an image rotation script in PHP. I could not find one that would do what I need (at least not in my searches), so after reading if you know of one that will accomplish what I need let me know, otherwise here is what I have going on.
The web site is for a motorsports business that carries lines of boats, motorcycles, atv, and other water craft (jet skis etc). On each page, there needs to be a photo gallery of thumbnails representing current models (boats.php will have boat images etc). These thumbnails will then load a larger image when clicked on.
Now the tricky part: I need it to be placed in tables. So, you have a table with X number of thumbnails in colums. In the next table/cell to the right is where the large image is placed. When a visitor clicks on a thumbnail, I need the larger image to "rotate" to show the current selection.
I have the code to display a simple table with 1 row of thumbnails. I plan to incorporate all of the data from a MySql DB later in the programming process.
Is there a way to call a function via an href link? or is there some other trick I have missed that you can use to call a function via a click (similar to a onMouseClick). Or would I be better off figuring this out with javascript?
The code below shows that I have created an array to hold the thumbnail urls and print the table containing them. This is in functions.php then in index.php I instantiate the ImageRotator class, fill the array and create the placeholder for the large image. How do I then load the large images via a function that is called when you click on the image?
functions.php code:
Code:
<?php
class imageRotator
{
var $thumbUrl = array();
var $pageLocation;
function addThumbs()
{
for($x=0; $x<func_num_args(); $x++)
{
$thumbUrl[] = func_get_arg($x);
}//end for
foreach($thumbUrl as $url)
{
print "<td width=\"25%\"><a href=\"$url\"><img src=\"$url\"></img></a></td>"; //the href is where the function call to rotate should happen
}//end foreach
}//end function addThumbs
function rotate($imageLargeUrl)
{
$pageLocation = $imageLargeUrl;
}
}//end class imageRotator
?>
index.php code:
Code:
<?php
include_once("includes/functions.php");
?>
<html>
<head>
<title>ImageRotator Test</title>
</head>
<body>
<table width="85%" border="1">
<tr>
<?php
$images = new imageRotator();
$images->addThumbs("images/thumb1.jpg", "images/thumb2.jpg", "images/thumb3.jpg", "images/thumb4.jpg");
?>
</tr>
<tr><td>
<?php
print $images->$pageLocation;
?>
</td></tr>
</table>
</body>
</html>
Basically in the functions.php addThumbs() function, I need this line:
print "<td width=\"25%\"><a href=\"$url\"><img src=\"$url\"></img></a></td>";
to call the function in the <a href> section if possible or a way to do this.
I had thought about loading index.php with an argument to do this, but I want to stay away from url strings if possible.
Let me know if I have no clue what I am doing (which I already know I don't since I am really just getting into PHP after letting dreamweaver do most of it for me in the past), or if javascript would work better (which I know even less than PHP) or if you know of something that exists for this already. I have also thought about just doing a flash version, but I would like to stay away from that as well if possible.
Any help is appreciated![/code]