<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kevin Dubois &#187; php</title>
	<atom:link href="http://kevindubois.com/blog/category/web-dev/php-web-dev/feed/" rel="self" type="application/rss+xml" />
	<link>http://kevindubois.com/blog</link>
	<description>A LAMP consultant in the greater Salt Lake City Area</description>
	<lastBuildDate>Mon, 24 Oct 2011 16:32:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Database driven jQuery rotating slide show with text navigation and links using the cycle plugin</title>
		<link>http://kevindubois.com/blog/2009/07/29/database-driven-jquery-rotating-slide-show-with-text-navigation-and-links-using-the-cycle-plugin/</link>
		<comments>http://kevindubois.com/blog/2009/07/29/database-driven-jquery-rotating-slide-show-with-text-navigation-and-links-using-the-cycle-plugin/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 17:53:15 +0000</pubDate>
		<dc:creator>Kevin Dubois</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://kevindubois.com/blog/?p=33</guid>
		<description><![CDATA[Tweet This tutorial will help you make a database driven slide show that has a navigation bar with text links to each slide, a pause button and the slides also have a database driven link.  I&#039;ll assume you know how &#8230; <a href="http://kevindubois.com/blog/2009/07/29/database-driven-jquery-rotating-slide-show-with-text-navigation-and-links-using-the-cycle-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="border:1px solid #808080;background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fkevindubois.com%2Fblog%2F2009%2F07%2F29%2Fdatabase-driven-jquery-rotating-slide-show-with-text-navigation-and-links-using-the-cycle-plugin%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://kevindubois.com/blog/2009/07/29/database-driven-jquery-rotating-slide-show-with-text-navigation-and-links-using-the-cycle-plugin/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://kevindubois.com/blog/2009/07/29/database-driven-jquery-rotating-slide-show-with-text-navigation-and-links-using-the-cycle-plugin/"  data-text="Database driven jQuery rotating slide show with text navigation and links using the cycle plugin" data-count="horizontal">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://kevindubois.com/blog/2009/07/29/database-driven-jquery-rotating-slide-show-with-text-navigation-and-links-using-the-cycle-plugin/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://kevindubois.com/blog/2009/07/29/database-driven-jquery-rotating-slide-show-with-text-navigation-and-links-using-the-cycle-plugin/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>This tutorial will help you make a database driven slide show that has a navigation bar with text links to each slide, a pause button and the slides also have a database driven link.  I&#039;ll assume you know how to get the records in the database and how to read the php code because you will need to define the location of your images and get the code to connect to your database.</p>
<p><a title="Database driven jquery rotating slideshow demo" href="http://kevindubois.com/demos/database_driven_jquery_slideshow_with_text_navigation.php" target="_blank">See a demo of this tutorial here</a></p>
<p><a title="Database driven jquery rotating slideshow demo zip" href="http://www.kevindubois.com/blog/attachments/database_driven_jquery_slideshow_with_text_navigation.zip" target="_self"> Download the source code</a> (all crammed into 1 php file for your convenience).  You will also need <a title="jquery" href="http://jquery.com/" target="_blank">jquery</a>, the <a title="jquery cycle plugin" href="http://malsup.com/jquery/cycle/" target="_blank">cycle</a> plugin and optionally the <a title="easing plugin for jquery" href="http://gsgd.co.uk/sandbox/jquery/easing/" target="_blank">easing</a> plugins for jquery.</p>
<p>First, we&#039;ll need to create a folder with some images.  My folder is called slide_img and is a child folder of my php file.</p>
<p>We&#039;ll also need to create a table in the database:</p>
<blockquote><p>CREATE TABLE `slide_items` (</p>
<p>`id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,<br />
`filename` VARCHAR( 200 ) NOT NULL ,<br />
`title` VARCHAR( 50 ) NOT NULL ,<br />
`link` VARCHAR( 500 ) NOT NULL ,</p>
<p>UNIQUE (`filename`)</p>
<p>) ENGINE = MYISAM</p></blockquote>
<p>You&#039;ll probably want to insert some records &#8211; these are based on the images I have in my demo &#8211; but the filename should correspond with the filename of the images in your slide_img folder.  Typically you would sync this all up with an admin tool where you would have a form for the title and link and an upload field for the image, but that&#039;s out of the scope of this article.</p>
<blockquote><p>INSERT INTO `slide_items` (</p>
<p>`id` ,`filename` ,`title` ,`link`</p>
<p>)<br />
VALUES</p>
<p>(NULL , &#039;1.jpg&#039;, &#039;glacier NP&#039;, &#039;http://www.kevindubois.com&#039;),</p>
<p>(NULL , &#039;2.jpg&#039;, &#039;Blodgett Canyon&#039;, &#039;http://www.duboistechnologies.com&#039;),</p>
<p>(NULL , &#039;3.jpg&#039;, &#039;Tree at Ridge&#039;, &#039;http://www.google.com&#039;),</p>
<p>(NULL , &#039;4.jpg&#039;, &#039;Sheep Mtn Bowl&#039;, &#039;http://www.kevindubois.com/blog&#039;);</p></blockquote>
<p>Now that we have the database and image folder set up, we can dive into the code.   The slide class contains all the database interactions, so let&#039;s start with that.  The class has 2 main functions: get_slides() retrieves the records from the database and show_slides() loops over the records and returns a variable that contains the html for all the images and their corresponding links.  For more detail, read the comments in the code:</p>
<blockquote><p>class Slide{<br />
// where are the images stored?<br />
var $imgfolder      = &#034;/demos/slide_img/&#034;;<br />
var $dbconnection   = false;<br />
// =============================================<br />
// Method      : constructor<br />
// Paramaters  : none<br />
// Return Value: none<br />
// Purpose     : instantiate the database connection<br />
// Author      : Kevin Dubois<br />
// =============================================<br />
public function __construct()<br />
{<br />
// connect to database &#8211; replace the xxx with your database connection settings<br />
$this-&gt;dbconnection = mysql_connect(&#039;xxxx&#039;, &#039;xxxxx&#039;, &#039;xxxxx&#039;) or die(&#034;Database Connection Failure&#034;);<br />
mysql_select_db(&#034;xxxx&#034;, $this-&gt;dbconnection) or die(&#034;Database not found&#034;);</p>
<p>}</p>
<p>// =============================================<br />
// Method      : destruct<br />
// Paramaters  : none<br />
// Return Value: none<br />
// Purpose     : close the database connection<br />
// Author      : Kevin Dubois<br />
// =============================================<br />
public function __destruct(){<br />
// close db connection<br />
mysql_close($this-&gt;dbconnection);<br />
}</p>
<p>// =============================================<br />
// Method      :  get_slides()<br />
// Paramaters  :  none<br />
// Return Value:  array slides: all database records<br />
// Purpose     :  get all slides<br />
// Author      :  Kevin Dubois<br />
// =============================================<br />
public function get_slides()<br />
{<br />
// get slides from db query<br />
$query = &#034;  SELECT id, filename, title, link<br />
FROM slide_items<br />
ORDER BY id ASC&#034;;<br />
// send query to db<br />
$result = mysql_query($query);<br />
// define $slides<br />
$slides = array();<br />
// loop over the records and populate the slides array<br />
while($row = mysql_fetch_assoc($result)){<br />
$slides[] = $row;<br />
}</p>
<p>return $slides;</p>
<p>}</p>
<p>public function show_slides(){<br />
// get the slides from db<br />
$files = $this-&gt;get_slides();<br />
// define $file_links<br />
$file_links = &#034;;<br />
// loop over db records and create the image html code<br />
foreach($files as $file){<br />
$file_links .= &lt;&lt;&lt;EOD<br />
&lt;a href=&#034;{$file['link']}&#034; id=&#034;{$file['filename']}&#034; title=&#034;{$file['title']}&#034;&gt;<br />
&lt;img alt=&#034;{$file['title']}&#034;  src=&#034;..{$this-&gt;imgfolder}{$file['filename']}&#034; /&gt;<br />
&lt;/a&gt;<br />
EOD;<br />
}</p>
<p>return $file_links;<br />
}<br />
}</p></blockquote>
<p>Now that we have the functionality to retreive the images, we can start with the html (with just a tiny bit of php injected).   Basically, I&#039;ll call the various jquery files, call the cycle function and let the cycle plugin do most of the work.  I have also integrated a navigation menu that floats on top of the images.  The css is also right in the code for the sake of clarity in this article, but you should probably save it in a separate css file. Refer to inline comments for more detail, or comment on this article and I will do my best to reply asap.</p>
<blockquote><p>&lt;?php</p>
<p>// the slide class can either be imported with an include or simply pasted here</p>
<p>// call the slide class<br />
$slide = new Slide();</p>
<p>// now print the html<br />
?&gt;</p>
<p>&lt;!&#8211; Call jquery files &#8211;&gt;<br />
&lt;script src=&#034;../js/jquery.js&#034; type=&#034;text/javascript&#034;&gt;&lt;/script&gt;<br />
&lt;script src=&#034;../js/jquery.cycle.js&#034; type=&#034;text/javascript&#034;&gt;&lt;/script&gt;<br />
&lt;script src=&#034;../js/jquery.easing.js&#034; type=&#034;text/javascript&#034;&gt;&lt;/script&gt;</p>
<p>&lt;script type=&#034;text/javascript&#034;&gt;<br />
$(document).ready(function(){<br />
// make the background of the nav bar transparent<br />
$(&#034;#slide-background&#034;).fadeTo(0,0.65);</p>
<p>// instantiate the slideshow<br />
$(&#039;#slideshow&#039;).show();<br />
// define the slideshow parameters (see http://malsup.com/jquery/cycle/ for more info)<br />
$(&#039;#slideshow&#039;).cycle({<br />
fx:         &#039;scrollLeft&#039;,<br />
timeout:     5000,<br />
pager:      &#039;#slidenav&#039;,<br />
// callback fn that creates the links for navigation<br />
pagerAnchorBuilder: function(idx, slide) {<br />
return &#039;&lt;a href=&#034;#&#034; style=&#034;font-size:9px&#034;&gt;&#039;+slide.title+&#039;&lt;/a&gt;&#039;;<br />
},<br />
pagerEvent: &#039;mouseover&#039;,<br />
fastOnEvent: true,<br />
fit:         1,<br />
pause: 1,<br />
pauseOnPagerHover: 1<br />
});</p>
<p>// code for the pause button<br />
$(&#034;#pbtn&#034;).click(function () {<br />
var pbtn = $(&#034;#pbtn&#034;).html();<br />
if(pbtn.toLowerCase() == &#039;&lt;a&gt;||&lt;/a&gt;&#039;){<br />
$(&#034;#slideshow&#034;).cycle(&#039;pause&#039;);<br />
$(&#034;#pbtn&#034;).html(&#039;&lt;a&gt;&amp;gt;&lt;/a&gt;&#039;);<br />
} else{<br />
$(&#034;#slideshow&#034;).cycle(&#039;resume&#039;);<br />
$(&#034;#pbtn&#034;).html(&#039;&lt;a&gt;||&lt;/a&gt;&#039;);<br />
}<br />
});</p>
<p>// slide down the navigation links<br />
$(&#039;#slide-text&#039;).slideDown();<br />
});</p>
<p>&lt;/script&gt;</p>
<p>&lt;style type=&#034;text/css&#034;&gt;<br />
body{font-size:16px}<br />
#slidenav { display:inline; line-height:20px }<br />
#slidenav a { margin: 0.5em; padding: 0.5em 1em; text-decoration: none;color:#FFF  }<br />
#slidenav a:hover{color:#FFF}<br />
#pbtn a { margin: 0.5em; padding: 0.5em 1em;  text-decoration: none;  }<br />
#slidenav a.activeSlide { background: #F00; color: #FFF }<br />
#slidenav a:focus { outline: none; }<br />
#pbtn a:focus { outline: none; }<br />
.slideimg{width:50em; border:0}<br />
.pics{display:none}<br />
#pbtn{cursor: pointer; margin: 1em; display:inline; font-size:0.8em}</p>
<p>#slidenavmenu{position:relative;z-index:100; zoom:1}</p>
<p>#slide-background{<br />
position:absolute;<br />
top:21px;<br />
background-color:#555;<br />
width:50em;<br />
left:0em;<br />
font-size:1em;<br />
line-height:20px;<br />
}<br />
#slide-text{<br />
position:absolute;<br />
width:50em;<br />
left:0px;<br />
text-align:center;<br />
color:white;<br />
top:20px;<br />
padding-left:0.2em;<br />
display:none;<br />
font-weight:bold;<br />
font-family: verdana, sans-serif;<br />
font-size:1em;<br />
}</p>
<p>&lt;/style&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;</p>
<p>&lt;div id=&#034;slidenavmenu&#034; &gt;<br />
&lt;div id=&#034;slide-background&#034;&gt;&amp;nbsp;&lt;/div&gt;<br />
&lt;div id=&#034;slide-text&#034;&gt;<br />
&lt;div id=&#034;slidenav&#034;&gt;&lt;/div&gt;<br />
&lt;div id=&#034;pbtn&#034; &gt;&lt;a&gt;||&lt;/a&gt;&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;/div&gt;</p>
<p>&lt;div id=&#034;slideshow&#034;&gt;<br />
&lt;?=$slide-&gt;show_slides()?&gt;<br />
&lt;/div&gt;</p>
<p>&lt;/body&gt;<br />
&lt;/html&gt;</p></blockquote>
<p>unless I forgot something, that&#039;s really all there is to it.  You can easily customize this widget to your pleasing &#8211; just make sure you sync up the filename of the images and the filename fields in the database table, and then play around with the css and the  jquery cycle settings, which you can find more information about on the <a title="cycle plugin" href="http://malsup.com/jquery/cycle/" target="_blank">cycle plugin site</a> .  Let me know if you need me to explain anything in more detail, I know I haven&#039;t written too much detail but the comments in the code should really help to get the gist of it.</p>
<p class="buymebeer"><form action="https://www.paypal.com/cgi-bin/webscr" target="paypal" method="post"><input type="hidden" name="cmd" value="_xclick" /><input type="hidden" name="business" value="kevin.dubois@gmail.com" /><input type="hidden" name="return" value="" /><input type="hidden" name="item_name" value="Buy Me a Beer for Database driven jQuery rotating slide show with text navigation and links using the cycle plugin" /><input type="hidden" name="currency_code" value="USD" /><input type="hidden" name="amount" value="1" /><input type="image" src="http://kevindubois.com/blog/wp-content/plugins/buy-me-beer/icon_beer.gif" align="left" alt="" title="" hspace="3" /></form><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;business=kevin.dubois@gmail.com&amp;currency_code=USD&amp;amount=1&amp;return=&amp;item_name=Buy+Me+a+Beer+for+Database+driven+jQuery+rotating+slide+show+with+text+navigation+and+links+using+the+cycle+plugin" target="paypal">Was this post helpful? Buy me a drink :-)</a></p>]]></content:encoded>
			<wfw:commentRss>http://kevindubois.com/blog/2009/07/29/database-driven-jquery-rotating-slide-show-with-text-navigation-and-links-using-the-cycle-plugin/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Rotating images using jQuery Ajax</title>
		<link>http://kevindubois.com/blog/2009/03/03/rotating-images-jquery-ajax/</link>
		<comments>http://kevindubois.com/blog/2009/03/03/rotating-images-jquery-ajax/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 23:20:21 +0000</pubDate>
		<dc:creator>Kevin Dubois</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[slideshow]]></category>

		<guid isPermaLink="false">http://kevindubois.com/blog/?p=13</guid>
		<description><![CDATA[Tweet There are many ways to rotate images on a website.  In my case, I needed a way to rotate all images from a particular folder, and I wanted it so that I just have to dump images in the &#8230; <a href="http://kevindubois.com/blog/2009/03/03/rotating-images-jquery-ajax/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="border:1px solid #808080;background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fkevindubois.com%2Fblog%2F2009%2F03%2F03%2Frotating-images-jquery-ajax%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://kevindubois.com/blog/2009/03/03/rotating-images-jquery-ajax/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://kevindubois.com/blog/2009/03/03/rotating-images-jquery-ajax/"  data-text="Rotating images using jQuery Ajax" data-count="horizontal">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://kevindubois.com/blog/2009/03/03/rotating-images-jquery-ajax/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://kevindubois.com/blog/2009/03/03/rotating-images-jquery-ajax/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>There are many ways to rotate images on a website.  In my case, I needed a way to rotate all images from a particular folder, and I wanted it so that I just have to dump images in the folder in order for the slideshow to pick them up.  ** NOTE: if you want a more advanced setup with database driven slides visit my <a title="Database driven jquery rotating slideshow demo" href="http://kevindubois.com/blog/2009/07/29/database-driven-jquery-rotating-slide-show-with-text-navigation-and-links-using-the-cycle-plugin/" target="_blank">post about database driven slideshows</a></p>
<p>For this tutorial I&#039;m going to use jQuery&#039;s framework and crossSlide, a plugin for jQuery which will allow smooth transitions between the images.  If you don&#039;t have it already, you can get jQuery at <a title="www.jquery.com" href="http://www.jquery.com" target="_blank">www.jquery.com</a> and the crossSlide plugin at <a title="www.gruppo4.com/~tobia/cross-slide.shtml" href="http://www.gruppo4.com/~tobia/cross-slide.shtml" target="_blank">www.gruppo4.com/~tobia/cross-slide.shtml</a> .  You&#039;ll also have to create a folder with images.  You&#039;ll get the best result if all images are identical in size.</p>
<p>A working example can be found at <a title="duboistechnologies.com" href="http://www.duboistechnologies.com">duboistechnologies.com</a> .</p>
<p>Download the code <a title="rotate images zip" href="http://kevindubois.com/blog/attachments/rotate_images.zip" target="_self">here</a></p>
<p>Ok, first things first: we&#039;ll need a placeholder for the images.  We&#039;ll need to specify a fixed height for this placeholder too, otherwise the content below will be jumping up and down every time a new image is loaded:</p>
<blockquote><p>&lt;div id=&#034;imgcontainer&#034; style=&#034;margin:0; width:46em; height:20em;&#034;&gt;<br />
&lt;img src=&#034;img/ajax-loader.gif&#034; style=&#034;margin-top:20%&#034; alt=&#034;loading&#8230;&#034; id=&#034;mainImg&#034; /&gt;<br />
&lt;/div&gt;</p></blockquote>
<p>I put an image in the div that will show an icon while the images are loaded&#8230;</p>
<p>Next step is to create a php page with some code to get all images from the folder.   The getfiles function will get all files and return a string that will be formatted so it can be parsed as separate objects by the javascript eval() function&#8230; but that&#039;s for later.  We just echo this string so our ajax call will pick it up.  The only thing you&#039;ll need to customize is the &#039;imagefolder&#039;&#8230; change this to whatever the name or path is to your folder:</p>
<blockquote><p>&lt;?php</p>
<p>echo getfiles(&#039;imagefolder&#039;);</p>
<p>function getfiles($folder=&#034;, $extensions=&#039;.*&#039;)<br />
{</p>
<p>// path:<br />
$folder = trim($folder);<br />
$folder = ($folder == &#034;) ? &#039;./&#039; : $folder;</p>
<p>// validate folder<br />
if (!is_dir($folder)){ die(&#039;invalid folder given!&#039;); }</p>
<p>// create files array<br />
$files = array();</p>
<p>// open directory<br />
if ($dir = @opendir($folder)){</p>
<p>// get all files:<br />
while($file = readdir($dir)){</p>
<p>if (!preg_match(&#039;/^\.+$/&#039;, $file) and<br />
preg_match(&#039;/\.(&#039;.$extensions.&#039;)$/&#039;, $file)){</p>
<p>// feed the array:<br />
$files[] = $file;<br />
}<br />
}<br />
// close directory<br />
closedir($dir);<br />
}<br />
else {<br />
die(&#039;Could not open the folder &#034;&#039;.$folder.&#039;&#034;&#039;);<br />
}</p>
<p>if (count($files) == 0){<br />
die(&#039;No files where found <img src='http://kevindubois.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> &#039;);<br />
}<br />
// shuffle the array so we have a random sequence of images<br />
shuffle($files);</p>
<p>$return = &#034;;<br />
foreach($files as $file){<br />
// format the string so we can later parse it into objects in javascript<br />
$return .= &#034;{&#039;src&#039;:'{$folder}/{$file}&#039;},&#034;;<br />
}<br />
$return = &#034;[".substr($return, 0,-1)."]&#034;;</p>
<p>// return the string:<br />
return $return;</p>
<p>}</p>
<p>?&gt;</p></blockquote>
<p>What we need to do now is set up an ajax call that gets the string of images the above function found in my images folder.  We&#039;ll also have to include the jquery and crossSlide packages:</p>
<blockquote><p>&lt;script type=&#034;text/javascript&#034; src=&#034;js/jquery.js&#034;&gt;&lt;/script&gt;<br />
&lt;script type=&#034;text/javascript&#034; src=&#034;js/jquery.cross-slide.js&#034;&gt;&lt;/script&gt;</p>
<p>&lt;script type=&#034;text/javascript&#034;&gt;<br />
$(document).ready(function(){loadImage();})</p>
<p>function loadImage(){<br />
// getimage.php is the php file that gets my images from the images folder<br />
$.post(&#034;getimage.php&#034;, function(data){<br />
if(data.length &gt;0) {<br />
// evaluate the string to a group of objects<br />
myObject = eval(data);<br />
// create a slideshow with the image objects and drop them in the placeholder<br />
$(&#039;#imgcontainer&#039;).crossSlide({sleep:5,fade:2},myObject);<br />
}<br />
});</p>
<p>}<br />
&lt;/script&gt;</p></blockquote>
<p>That&#039;s all there is to it.  This is a great alternative to flash and is much less cpu intensive!</p>
<p class="buymebeer"><form action="https://www.paypal.com/cgi-bin/webscr" target="paypal" method="post"><input type="hidden" name="cmd" value="_xclick" /><input type="hidden" name="business" value="kevin.dubois@gmail.com" /><input type="hidden" name="return" value="" /><input type="hidden" name="item_name" value="Buy Me a Beer for Rotating images using jQuery Ajax" /><input type="hidden" name="currency_code" value="USD" /><input type="hidden" name="amount" value="1" /><input type="image" src="http://kevindubois.com/blog/wp-content/plugins/buy-me-beer/icon_beer.gif" align="left" alt="" title="" hspace="3" /></form><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;business=kevin.dubois@gmail.com&amp;currency_code=USD&amp;amount=1&amp;return=&amp;item_name=Buy+Me+a+Beer+for+Rotating+images+using+jQuery+Ajax" target="paypal">Was this post helpful? Buy me a drink :-)</a></p>]]></content:encoded>
			<wfw:commentRss>http://kevindubois.com/blog/2009/03/03/rotating-images-jquery-ajax/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
	</channel>
</rss>

