Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-24-2004, 03:34 PM
southplatte's Avatar
WebProWorld Veteran
 

Join Date: Jul 2003
Location: Colorado
Posts: 381
southplatte RepRank 1
Default PHP Function Calls via Links?

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]
Reply With Quote
  #2 (permalink)  
Old 07-26-2004, 01:00 AM
Easywebdev's Avatar
WebProWorld Veteran
 

Join Date: Apr 2004
Posts: 328
Easywebdev RepRank 1
Default

Give your large image a name, ie

[img][/img][img]'.$thumb_dir.$url.'[/img]</img></td>';

Now just pass the filenames to addThumbs
$images->addThumbs("thumb1.jpg", "thumb2.jpg"); etc.

[/edit]
You might want to copy and paste the print line to get the single/double quotes right.

Regards, Eamonn.
__________________
"I have not failed. I have found 10,000 ways that don't work" - Thomas Edison.
"The secret to creativity is knowing how to hide your sources" - Albert Einstein.
Reply With Quote
  #3 (permalink)  
Old 07-27-2004, 11:00 AM
southplatte's Avatar
WebProWorld Veteran
 

Join Date: Jul 2003
Location: Colorado
Posts: 381
southplatte RepRank 1
Default

Easywebdev,

Thanks for the help and insight. I figured something like the onClick to set it, but I couldn't figure out how to do that, and the idea of the two directories compeletely escaped me.

Well, I am off to implement it, and will post back if I run into any more trouble. Thanks again!
Reply With Quote
  #4 (permalink)  
Old 07-27-2004, 11:59 AM
southplatte's Avatar
WebProWorld Veteran
 

Join Date: Jul 2003
Location: Colorado
Posts: 381
southplatte RepRank 1
Default

Thank-you, thank-you, thank-you. The modifications worked perfect, and your help is very much appreciated!! Again, thank-you very much!
Reply With Quote
  #5 (permalink)  
Old 07-27-2004, 11:47 PM
Easywebdev's Avatar
WebProWorld Veteran
 

Join Date: Apr 2004
Posts: 328
Easywebdev RepRank 1
Default

Glad to be of assistance.
__________________
"I have not failed. I have found 10,000 ways that don't work" - Thomas Edison.
"The secret to creativity is knowing how to hide your sources" - Albert Einstein.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , , , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0