<?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>Free Web Resources - Web Resources Depot &#187; Tutorials</title>
	<atom:link href="http://www.webresourcesdepot.com/category/extras/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webresourcesdepot.com</link>
	<description>Free Web Resources</description>
	<lastBuildDate>Sun, 12 Feb 2012 13:06:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Ajax Poll Script With PHP, MySQL &amp; jQuery</title>
		<link>http://www.webresourcesdepot.com/ajax-poll-script-with-php-mysql-jquery/</link>
		<comments>http://www.webresourcesdepot.com/ajax-poll-script-with-php-mysql-jquery/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 09:54:53 +0000</pubDate>
		<dc:creator>Umut M.</dc:creator>
				<category><![CDATA[Extras]]></category>
		<category><![CDATA[Goodies]]></category>
		<category><![CDATA[Licenses]]></category>
		<category><![CDATA[Other License]]></category>
		<category><![CDATA[Polls & Surveys]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Mysql]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.webresourcesdepot.com/?p=1704</guid>
		<description><![CDATA[<p><a href='http://rss.buysellads.com/click.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=1704&c=16634' target='_blank'><img src='http://rss.buysellads.com/img.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=1704&c=16634' border='0' alt='' /></a></p><p><a href='http://buysellads.com/buy/sitedetails/pubkey/ed230295611f656daf3115e6d682ca7d/zone/1259982' target='_blank'>Advertise here with BSA</a></p><br />In this tutorial, we&#39;ll be creating an Ajax Poll Script that displays the results with colored and animated lines using PHP, MySQL and jQuery. The script has a pretty easy logic and can be implemented into any website quickly by simply calling a php function like getPoll(2) which brings the second poll. The code has [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://rss.buysellads.com/click.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=1704&c=29157' target='_blank'><img src='http://rss.buysellads.com/img.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=1704&c=29157' border='0' alt='' /></a></p><p><a href='http://buysellads.com/buy/sitedetails/pubkey/ed230295611f656daf3115e6d682ca7d/zone/1259982' target='_blank'>Advertise here with BSA</a></p><br /><p>In this tutorial, we&#39;ll be creating an <strong>Ajax Poll Script</strong> that <strong>displays the results with colored and animated lines</strong> using PHP, MySQL and jQuery.</p>
<p>The script has a pretty easy logic and can be <strong>implemented into any website quickly</strong> by simply calling a php function like <code>getPoll(2)</code> which brings the second poll.</p>
<p><a href="http://webresourcesdepot.com/wp-content/uploads/file/ajax-poll-script/"><img alt="Ajax Poll Script" height="254" src="http://www.webresourcesdepot.com/wp-content/uploads/ajax-poll-script.gif" width="480" /></a></p>
<p><a href="http://webresourcesdepot.com/wp-content/uploads/file/ajax-poll-script/"><img alt="Ajax Poll Script Demo" height="48" src="http://www.webresourcesdepot.com/wp-content/uploads/image/demo-button.gif" style="border: 0px none;" width="480" /></a><a href="http://www.webresourcesdepot.com/?download=AjaxPollScript"><img alt="Ajax Poll Script Download" src="http://www.webresourcesdepot.com/wp-content/uploads/image/download-no-rss-button.gif" style="border: 0px none;" /></a></p>
<p>The code has 3 parts: HTML, JavaScript (jQuery) and PHP. Let&#39;s start with the easiest one:</p>
<p><span id="more-1704"></span></p>
<h3>HTML</h3>
<p>The <strong>HTML for the poll is generated within the PHP function </strong>which is usually nice as it is only a 1-line-code and doesn&#39;t create a visual pollution in the overall HTML.</p>
<p><pre class="brush: html">
&lt;div id=&quot;pollWrap&quot;&gt;
    &lt;form name=&quot;pollForm&quot; method=&quot;post&quot; action=&quot;inc/functions.php?action=vote&quot;&gt;
        &lt;h3&gt;Poll Question 1&lt;/h3&gt;
        &lt;ul&gt;
            &lt;li&gt;
                &lt;input name=&quot;pollAnswerID&quot; id=&quot;pollRadioButton1&quot; value=&quot;1&quot; type=&quot;radio&quot;&gt;
                Answer1 for Poll1
                &lt;span id=&quot;pollAnswer1&quot;&gt;&lt;/span&gt;
			&lt;/li&gt;
            &lt;li class=&quot;pollChart pollChart1&quot;&gt;&lt;/li&gt;
            &lt;li&gt;
                &lt;input name=&quot;pollAnswerID&quot; id=&quot;pollRadioButton2&quot; value=&quot;2&quot; type=&quot;radio&quot;&gt;
                Answer2 for Poll1
                &lt;span id=&quot;pollAnswer2&quot;&gt;&lt;/span&gt;
            &lt;/li&gt;
            &lt;li class=&quot;pollChart pollChart2&quot;&gt;&lt;/li&gt;
        &lt;/ul&gt;
        &lt;input name=&quot;pollSubmit&quot; id=&quot;pollSubmit&quot; value=&quot;Vote&quot; type=&quot;submit&quot;&gt;
        &lt;span id=&quot;pollMessage&quot;&gt;&lt;/span&gt;
        &lt;img src=&quot;ajaxLoader.gif&quot; alt=&quot;Ajax Loader&quot; id=&quot;pollAjaxLoader&quot;&gt;
    &lt;/form&gt;
&lt;/div&gt;
</pre>
</p>
<p>There is nothing original here. In one of the list items, we mention the answer and provide a unique ID for it which matches that answer&#39;s answerID in the database. For the other list item, we reserve it for the colored line, again by giving it the unique ID.</p>
<h3>PHP</h3>
<p>We first include our db connection file and handle the posted items from the Ajax requests</p>
<p><pre class="brush: php">
require(&quot;db.php&quot;);
//GETTING VARIABLES START
$action 		= mysql_real_escape_string($_POST[&#039;action&#039;]);
$pollAnswerID	= mysql_real_escape_string($_POST[&#039;pollAnswerID&#039;]);
//GETTING VARIABLES END
</pre>
</p>
<p>After that, create the function <code>getPoll</code> which simply loops through the database and creates the HTML for the poll mentioned above.</p>
<p><pre class="brush: php">
function getPoll($pollID){
	$query  = &quot;SELECT * FROM polls LEFT JOIN pollAnswers ON polls.pollID = pollAnswers.pollID WHERE polls.pollID = &quot; . $pollID . &quot; ORDER By pollAnswerListing ASC&quot;;
	$result = mysql_query($query);
	//echo $query;jquery

	while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{
		$pollQuestion 		= $row[&#039;pollQuestion&#039;];
		$pollAnswerID 		= $row[&#039;pollAnswerID&#039;];
		$pollAnswerValue	= $row[&#039;pollAnswerValue&#039;];

		if ($pollStartHtml == &#039;&#039;) {
			$pollStartHtml 	= &#039;&lt;div id=&quot;pollWrap&quot;&gt;&lt;form name=&quot;pollForm&quot; method=&quot;post&quot; action=&quot;inc/functions.php?action=vote&quot;&gt;&lt;h3&gt;&#039; . $pollQuestion .&#039;&lt;/h3&gt;&lt;ul&gt;&#039;;
			$pollEndHtml 	= &#039;&lt;/ul&gt;&lt;input type=&quot;submit&quot; name=&quot;pollSubmit&quot; id=&quot;pollSubmit&quot; value=&quot;Vote&quot; /&gt; &lt;span id=&quot;pollMessage&quot;&gt;&lt;/span&gt;&lt;img src=&quot;ajaxLoader.gif&quot; alt=&quot;Ajax Loader&quot; id=&quot;pollAjaxLoader&quot; /&gt;&lt;/form&gt;&lt;/div&gt;&#039;;
		}
		$pollAnswersHtml	= $pollAnswersHtml . &#039;&lt;li&gt;&lt;input name=&quot;pollAnswerID&quot; id=&quot;pollRadioButton&#039; . $pollAnswerID . &#039;&quot; type=&quot;radio&quot; value=&quot;&#039; . $pollAnswerID . &#039;&quot; /&gt; &#039; . $pollAnswerValue .&#039;&lt;span id=&quot;pollAnswer&#039; . $pollAnswerID . &#039;&quot;&gt;&lt;/span&gt;&lt;/li&gt;&#039;;
		$pollAnswersHtml	= $pollAnswersHtml . &#039;&lt;li class=&quot;pollChart pollChart&#039; . $pollAnswerID . &#039;&quot;&gt;&lt;/li&gt;&#039;;
	}
	echo $pollStartHtml . $pollAnswersHtml . $pollEndHtml;
}
</pre>
</p>
<p>This <code>getPollID</code> function below is for easily getting the ID of the related polls by providing an answerID:</p>
<p><pre class="brush: php">
function getPollID($pollAnswerID){
	$query  = &quot;SELECT pollID FROM pollAnswers WHERE pollAnswerID = &quot;.$pollAnswerID.&quot; LIMIT 1&quot;;
	$result = mysql_query($query);
	$row = mysql_fetch_array($result);

	return $row[&#039;pollID&#039;];
}
</pre>
</p>
<p>And, the getPollResults function which is kinda tricky but not that much.</p>
<p>When ran, it returns a string like: 1|13|#ffcc00-2|32|#00ff00-3|18|#cc0000-63&quot; which the first number is the answerID, second is the points it has and third is the color for that answer&#39;s animated line.</p>
<p>The last number is the sum of all points for easily calculating percentages.</p>
<p>The <strong>string is parsed in the JavaScript side</strong> later on.</p>
<p><pre class="brush: php">
function getPollResults($pollID){
	$colorArray = array(1 =&gt; &quot;#ffcc00&quot;, &quot;#00ff00&quot;, &quot;#cc0000&quot;, &quot;#0066cc&quot;, &quot;#ff0099&quot;, &quot;#ffcc00&quot;, &quot;#00ff00&quot;, &quot;#cc0000&quot;, &quot;#0066cc&quot;, &quot;#ff0099&quot;);
	$colorCounter = 1;
	$query  = &quot;SELECT pollAnswerID, pollAnswerPoints FROM pollAnswers WHERE pollID = &quot;.$pollID.&quot;&quot;;
	$result = mysql_query($query);
	while($row = mysql_fetch_array($result))
	{
		if ($pollResults == &quot;&quot;) {
			$pollResults = $row[&#039;pollAnswerID&#039;] . &quot;|&quot; . $row[&#039;pollAnswerPoints&#039;] . &quot;|&quot; . $colorArray[$colorCounter];
		} else {
			$pollResults = $pollResults . &quot;-&quot; . $row[&#039;pollAnswerID&#039;] . &quot;|&quot; . $row[&#039;pollAnswerPoints&#039;] . &quot;|&quot; . $colorArray[$colorCounter];
		}
		$colorCounter = $colorCounter + 1;
	}
	$query  = &quot;SELECT SUM(pollAnswerPoints) FROM pollAnswers WHERE pollID = &quot;.$pollID.&quot;&quot;;
	$result = mysql_query($query);
	$row = mysql_fetch_array( $result );
	$pollResults = $pollResults . &quot;-&quot; . $row[&#039;SUM(pollAnswerPoints)&#039;];
	echo $pollResults;
}
</pre>
</p>
<p>The last PHP code is the voting part which also sets a cookie:</p>
<p><pre class="brush: php">
if ($action == &quot;vote&quot;){

	if (isset($_COOKIE[&quot;poll&quot; . getPollID($pollAnswerID)])) {
		echo &quot;voted&quot;;
	} else {
		$query  = &quot;UPDATE pollAnswers SET pollAnswerPoints = pollAnswerPoints + 1 WHERE pollAnswerID = &quot;.$pollAnswerID.&quot;&quot;;
		mysql_query($query) or die(&#039;Error, insert query failed&#039;);
		setcookie(&quot;poll&quot; . getPollID($pollAnswerID), 1, time()+259200, &quot;/&quot;, &quot;.webresourcesdepot.com&quot;);
		getPollResults(1);
	}
}
</pre>
</p>
<h3>jQuery (JavaScript)</h3>
<p>It is only an Ajax request that posts the selected answer to the PHP code, gets the string in return, parses it and makes some show/hide tricks for displaying and hiding the messages or loaders.</p>
<p>Here it is:</p>
<p><pre class="brush: javascript">
$(document).ready(function() {   

	$(&quot;#pollAjaxLoader&quot;).hide(); //hide the ajax loader
	$(&quot;#pollMessage&quot;).hide(); //hide the ajax loader
	$(&quot;#pollSubmit&quot;).click(function() {
		var pollAnswerVal = $(&#039;input:radio[name=pollAnswerID]:checked&#039;).val();//Getting the value of a selected radio element.
		if ($(&#039;input:radio[name=pollAnswerID]:checked&#039;).length) {
			$(&quot;#pollAjaxLoader&quot;).show(); //show the ajax loader
			$.ajax({
				type: &quot;POST&quot;,
				url: &quot;inc/functions.php&quot;,
				data: { pollAnswerID: pollAnswerVal, action: &quot;vote&quot; },
				success: function(theResponse) {
					//the functions.php returns a response like &quot;1|13|#ffcc00-2|32|#00ff00-3|18|#cc0000-63&quot; which the first number is the answerID, second is the points it has and third is the color for that answer&#039;s graph. The last number is the sum of all points for easilt calculating percentages.
					if (theResponse == &quot;voted&quot;) {
						$(&quot;#pollAjaxLoader&quot;).hide(); //hide the ajax loader
						$(&quot;#pollMessage&quot;).html(&quot;sorry, you already voted.&quot;).fadeTo(&quot;slow&quot;, 1);
					} else {
						var numberOfAnswers 		= (theResponse).split(&quot;-&quot;).length-2;//calculate the number of answers
						var splittedResponse 		= (theResponse).split(&quot;-&quot;);
						var pollAnswerTotalPoints 	= splittedResponse[numberOfAnswers+1];

						for (i=0;i&lt;=numberOfAnswers;i++)
						{
							var splittedAnswer 		= (splittedResponse[i]).split(&quot;|&quot;);
							var pollAnswerID 		= (splittedAnswer[0]);
							var pollAnswerPoints 	= (splittedAnswer[1]);
							var pollAnswerColor 	= (splittedAnswer[2]);
							var pollPercentage		= (100 * pollAnswerPoints / pollAnswerTotalPoints);
							$(&quot;.pollChart&quot; + pollAnswerID).css(&quot;background-color&quot;,pollAnswerColor);
							$(&quot;.pollChart&quot; + pollAnswerID).animate({width:pollPercentage + &quot;%&quot;});
							$(&quot;#pollAnswer&quot; + pollAnswerID).html(&quot; (&quot; + Math.round(pollPercentage) + &quot;% - &quot; + pollAnswerPoints + &quot; votes)&quot;);
							$(&quot;#pollRadioButton&quot; + pollAnswerID).attr(&quot;disabled&quot;, &quot;disabled&quot;); //disable the radio buttons
						}
						$(&quot;#pollAjaxLoader&quot;).hide(); //hide the ajax loader again
						$(&quot;#pollSubmit&quot;).attr(&quot;disabled&quot;, &quot;disabled&quot;); //disable the submit button
					}
				}
			});
			return false; 

		} else {
			$(&quot;#pollMessage&quot;).html(&quot;please select an answer.&quot;).fadeTo(&quot;slow&quot;, 1, function(){
				setTimeout(function() {
					$(&quot;#pollMessage&quot;).fadeOut(&quot;slow&quot;);
				}, 3000);
			});
			return false;
		}

	});

});
</pre>
</p>
<p>The JavaScript code is well-commented and is pretty self-explanatory. Don&#39;t let the number of lines afraid you, most of them are just the make-up.</p>
<p>That&#39;s all.</p>
<p><strong>Special Downloads:</strong><br />
<a href="http://www.webresourcesdepot.com/?download=jBasket" target="_blank">Ajaxed Add-To-Basket Scenarios With jQuery And PHP</a><br />
<a href="http://www.webresourcesdepot.com/?download=Free-Admin-Template" target="_blank">Free Admin Template For Web Applications</a><br />
<a href="http://www.webresourcesdepot.com/?download=jQuery-Dynamic-Drag-Drop" target="_blank">jQuery Dynamic Drag&#8217;n Drop</a><br />
<a href="http://www.webresourcesdepot.com/?download=sTwitter-1-0" target="_blank">ScheduledTweets</a></p>
<p><strong>Advertisements:</strong><br />
<a href="http://www.admintemplates.com" target="_blank">Professional XHTML Admin Template ($15 Discount With The Code: WRD.)</a><br />
<a href="http://www.xhtmchop.com" target="_blank">Psd to Xhtml</a><br />
<a href="http://www.sslmatic.com" target="_blank">SSLmatic &#8211; Cheap SSL Certificates (from $19.99/year)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webresourcesdepot.com/ajax-poll-script-with-php-mysql-jquery/feed/</wfw:commentRss>
		<slash:comments>70</slash:comments>
		</item>
		<item>
		<title>FeedCount-Like Google Analytics Counter</title>
		<link>http://www.webresourcesdepot.com/feedcount-like-google-analytics-counter/</link>
		<comments>http://www.webresourcesdepot.com/feedcount-like-google-analytics-counter/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 09:22:14 +0000</pubDate>
		<dc:creator>Umut M.</dc:creator>
				<category><![CDATA[Extras]]></category>
		<category><![CDATA[Goodies]]></category>
		<category><![CDATA[No License]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Google Analytics]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.webresourcesdepot.com/?p=1422</guid>
		<description><![CDATA[<p><a href='http://rss.buysellads.com/click.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=1422&c=28669' target='_blank'><img src='http://rss.buysellads.com/img.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=1422&c=28669' border='0' alt='' /></a></p><p><a href='http://buysellads.com/buy/sitedetails/pubkey/ed230295611f656daf3115e6d682ca7d/zone/1259982' target='_blank'>Advertise here with BSA</a></p><br />FeedBurner&#39;s popular chicklet FeedCount is the most-used way to display the number of subscribers for a feed. Also, a similar design is used by TwitterCounter to display your Twitter followers. We&#39;ll be creating a dynamic FeedCount-like interface that can display your website&#39;s statistics like pageviews, visits, etc. (one or all of them) using PHP. At [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://rss.buysellads.com/click.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=1422&c=6360' target='_blank'><img src='http://rss.buysellads.com/img.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=1422&c=6360' border='0' alt='' /></a></p><p><a href='http://buysellads.com/buy/sitedetails/pubkey/ed230295611f656daf3115e6d682ca7d/zone/1259982' target='_blank'>Advertise here with BSA</a></p><br /><p><strong>FeedBurner&#39;s popular chicklet FeedCount</strong> is the most-used way to display the number of subscribers for a feed.</p>
<p>Also, a similar design is used by <strong>TwitterCounter</strong> to display your Twitter followers.</p>
<p>We&#39;ll be creating a <strong>dynamic FeedCount-like interface that can display your website&#39;s statistics</strong> like pageviews, visits, etc. (one or all of them) using PHP.</p>
<p><img alt="Google Analytics Counter" height="150" src="http://www.webresourcesdepot.com/wp-content/uploads/google-analytics-counter.gif" width="480" /></p>
<h3>At the end of this tutorial, we&#39;ll have 2 different counters:</h3>
<ul>
<li>a counter that can display only one metric &#8211; basic version</li>
<li>a counter that can display multiple metrics (some jQuery fun here) &#8211; advanced version</li>
</ul>
<p><a href="http://www.webresourcesdepot.com/wp-content/uploads/file/google-analytics-counter/index.php" target="_blank"><img style="border: 0px none ;" alt="Google Analytics Counter Demo" src="http://www.webresourcesdepot.com/wp-content/uploads/image/demo-button.gif" height="48" width="480"></a><a href="http://www.webresourcesdepot.com/?download=Google-Analytics-Counter"><img style="border: 0px none ;" alt="Google Analytics Counter Download" src="http://www.webresourcesdepot.com/wp-content/uploads/image/download-no-rss-button.gif"></a><br />
<span id="more-1422"></span></p>
<p>&nbsp;</p>
<h2>Basic Counter</h2>
<hr />
<p>Let&#39;s start with the PHP part:</p>
<h3>How To Fetch Google Analytics Data With PHP?</h3>
<p>We&#39;ll be using a <a href="http://code.google.com/p/gapi-google-analytics-php-interface/" target="_blank"><strong>PHP class named GAPI</strong></a> that makes using Google Analytics API so easy.</p>
<p>There are 3 variables we need to start using GAPI:</p>
<ul>
<li><strong>Google Analytics user </strong>that has access to the website stats to be displayed (<strong>I suggest creating a new Google Account specifically for this purpose</strong> and provide only read access to that website&#39;s data. This will prevent using your real Google account in your code which is a good step for security).</li>
<li>Google Analytics user password.</li>
<li>Profile ID of the website (it is <strong>not the one that starts with UA</strong>, rather, it is the ID that appears on browser&#39;s address bar when a report of that website is clicked).</li>
<p></
<ul>
<p>GAPI offers a simple usage to access Google Analytics data:</p>
<pre class="brush: php">
&lt;?php
define(&#039;ga_email&#039;,&#039;yourGoogleEmail&#039;);
define(&#039;ga_password&#039;,&#039;yourGooglePass&#039;);
define(&#039;ga_profile_id&#039;,&#039;yourProfileID&#039;);

require &#039;gapi.class.php&#039;;
$ga = new gapi(ga_email,ga_password);
$ga-&gt;requestReportData(ga_profile_id,array(&#039;browser&#039;,&#039;browserVersion&#039;),array(&#039;pageviews&#039;));
?&gt;
</pre>
<p>Now <strong>we have the pageviews data of the last 30 days</strong> (it is possible to define custom dates, check the GAPI docs.)</p>
<p>(If you want to read more on GAPI, <strong>code-diesel</strong> has a <a href="http://www.codediesel.com/php/reading-google-analytics-data-from-php/" target="_blank">great article on this class</a>.)</p>
<p>Here is the HTML:</p>
<pre class="brush: html">
&lt;div id=&quot;statsWrap&quot;&gt;
	&lt;div id=&quot;statsDetailsWrap&quot;&gt;
		&lt;div id=&quot;statsCount&quot;&gt;
			&lt;?php echo $ga-&gt;getPageviews() ?&gt;
		&lt;/div&gt;
		&lt;div id=&quot;statsMetric&quot;&gt;
			pageviews
		&lt;/div&gt;
	&lt;/div&gt;
	&lt;div id=&quot;byGoogle&quot;&gt;By Google Analytics&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>And CSS</p>
<pre class="brush: css">
#statsWrap {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 10px;
}
#statsDetailsWrap {
	background: #333333;
	float: left;
	padding: 1px 3px 1px 1px;
	border: #666666 1px inset;
}
#statsCount {
	float: left;
	padding: 1px 3px;
	background: #999999;
	color: #FFFFFF;
	border: #666666 1px inset;
}
#statsMetric {
	float: left;
	padding: 3px;
	color: #FFFFFF;
}
#byGoogle {
	clear: both;
	color: #666666;
	font-size: 10px;
}
</pre>
<p>&nbsp;</p>
<h2>Advanced Counter (With jQuery)</h2>
<hr />
<p>It is possible to fetch multiple data with GAPI &amp; we&#39;ll be creating an <strong>auto-rotating counter that can display multiple metrics (visits &amp; pageviews)</strong>.</p>
<p>Let&#39;s use a little improved version of the PHP code:</p>
<pre class="brush: php">
&lt;?php
define(&#039;ga_email&#039;,&#039;yourGoogleEmail&#039;);
define(&#039;ga_password&#039;,&#039;yourGooglePass&#039;);
define(&#039;ga_profile_id&#039;,&#039;yourProfileID&#039;);

require &#039;gapi.class.php&#039;;
$ga = new gapi(ga_email,ga_password);
$ga-&gt;requestReportData(ga_profile_id,array(&#039;browser&#039;,&#039;browserVersion&#039;),array(&#039;pageviews&#039;,&#039;visits&#039;));
?&gt;
</pre>
<p>And a tiny update to the HTML by adding few spans to wrap every metric so we can show/hide them.</p>
<pre class="brush: html">
&lt;div id=&quot;statsWrap&quot;&gt;
	&lt;div id=&quot;statsDetailsWrap&quot;&gt;
		&lt;div id=&quot;statsCount&quot;&gt;
			&lt;span id=&quot;statsPageviews&quot;&gt;&lt;?php echo $ga-&gt;getPageviews() ?&gt;&lt;/span&gt;
			&lt;span id=&quot;statsVisits&quot;&gt;&lt;?php echo $ga-&gt;getVisits() ?&gt;&lt;/span&gt;
		&lt;/div&gt;
		&lt;div id=&quot;statsMetric&quot;&gt;
			&lt;span id=&quot;statsPageviewsText&quot;&gt;pageviews&lt;/span&gt;
			&lt;span id=&quot;statsVisitsText&quot;&gt;visits&lt;/span&gt;
		&lt;/div&gt;
	&lt;/div&gt;
	&lt;div id=&quot;byGoogle&quot;&gt;By Google Analytics&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>I have also updated the CSS a little bit by adding hard-coded width-heights to elements to make sure they will look ok when rotating:</p>
<pre class="brush: css">
#statsWrap {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 10px;
}
#statsDetailsWrap {
	background: #333333;
	float: left;
	padding: 1px 3px 1px 1px;
	border: #666666 1px inset;
}
#statsCount {
	float: left;
	padding: 1px 3px;
	background: #999999;
	color: #FFFFFF;
	border: #666666 1px inset;
	width: 40px;
	height: 12px;
}
#statsMetric {
	float: left;
	padding: 3px;
	color: #FFFFFF;
	width: 50px;
	height: 12px;
}
#byGoogle {
	clear: both;
	color: #666666;
	font-size: 10px;
}
</pre>
<p>And here is the jQuery part which rotates metrics:</p>
<pre class="brush: js">
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function() {   

	$(&quot;#statsPageviews&quot;).hide();
	$(&quot;#statsVisits&quot;).hide();
	$(&quot;#statsPageviewsText&quot;).hide();
	$(&quot;#statsVisitsText&quot;).hide();
	rotateMetrics(); 

	function rotateMetrics() {
		$(&quot;#statsPageviewsText&quot;).slideDown(&quot;slow&quot;);
		$(&quot;#statsPageviews&quot;).slideDown(&quot;slow&quot;, function() {
			setTimeout(function() {
				$(&quot;#statsPageviewsText&quot;).slideUp(&quot;slow&quot;);
				$(&quot;#statsPageviews&quot;).slideUp(&quot;slow&quot;, function() {
					$(&quot;#statsVisitsText&quot;).slideDown(&quot;slow&quot;);
					$(&quot;#statsVisits&quot;).slideDown(&quot;slow&quot;, function() {
						setTimeout(function() {
							$(&quot;#statsVisitsText&quot;).slideUp(&quot;slow&quot;);
							$(&quot;#statsVisits&quot;).slideUp(&quot;slow&quot;, function() {
								rotateMetrics();
							});
						}, 3000);
					});
				});
			}, 3000);
		});

	}
});
&lt;/script&gt;
</pre>
<p>In the jQuery part, although it may look complicated, it is definitely not. We used callbacks for the slideUp/slideDown functions &#038; added a little delay between transitions.</p>
<p>That&#8217;s all.</p>
<p><strong>Special Downloads:</strong><br />
<a href="http://www.webresourcesdepot.com/?download=jBasket" target="_blank">Ajaxed Add-To-Basket Scenarios With jQuery And PHP</a><br />
<a href="http://www.webresourcesdepot.com/?download=Free-Admin-Template" target="_blank">Free Admin Template For Web Applications</a><br />
<a href="http://www.webresourcesdepot.com/?download=jQuery-Dynamic-Drag-Drop" target="_blank">jQuery Dynamic Drag&#8217;n Drop</a><br />
<a href="http://www.webresourcesdepot.com/?download=sTwitter-1-0" target="_blank">ScheduledTweets</a></p>
<p><strong>Advertisements:</strong><br />
<a href="http://www.admintemplates.com" target="_blank">Professional XHTML Admin Template ($15 Discount With The Code: WRD.)</a><br />
<a href="http://www.xhtmchop.com" target="_blank">Psd to Xhtml</a><br />
<a href="http://www.sslmatic.com" target="_blank">SSLmatic &#8211; Cheap SSL Certificates (from $19.99/year)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webresourcesdepot.com/feedcount-like-google-analytics-counter/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Ajaxed Sliding Shopping Cart With jQuery</title>
		<link>http://www.webresourcesdepot.com/ajaxed-sliding-shopping-cart-with-jquery/</link>
		<comments>http://www.webresourcesdepot.com/ajaxed-sliding-shopping-cart-with-jquery/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 08:53:24 +0000</pubDate>
		<dc:creator>Umut M.</dc:creator>
				<category><![CDATA[E-Commerce]]></category>
		<category><![CDATA[Extras]]></category>
		<category><![CDATA[MIT License]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.webresourcesdepot.com/?p=1084</guid>
		<description><![CDATA[<p><a href='http://rss.buysellads.com/click.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=1084&c=29647' target='_blank'><img src='http://rss.buysellads.com/img.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=1084&c=29647' border='0' alt='' /></a></p><p><a href='http://buysellads.com/buy/sitedetails/pubkey/ed230295611f656daf3115e6d682ca7d/zone/1259982' target='_blank'>Advertise here with BSA</a></p><br />With this 5th &#38; last post of the &#34;WRD E-Commerce Week&#34; we will be modifying &#34;our Ajaxed shopping cart&#34; to create a one which is very ideal for designs with limited spaces. The shopping cart will: be hidden at the top of the page that can be displayed with a show/hide link open when an [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://rss.buysellads.com/click.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=1084&c=25989' target='_blank'><img src='http://rss.buysellads.com/img.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=1084&c=25989' border='0' alt='' /></a></p><p><a href='http://buysellads.com/buy/sitedetails/pubkey/ed230295611f656daf3115e6d682ca7d/zone/1259982' target='_blank'>Advertise here with BSA</a></p><br /><p>With this 5th &amp; last post of the &quot;<a href="http://www.webresourcesdepot.com/e-commerce-week-at-webresourcesdepot-want-to-sponsor/">WRD E-Commerce Week</a>&quot; we will be modifying &quot;<a href="http://www.webresourcesdepot.com/creating-a-slick-ajaxed-add-to-basket-with-jquery-and-php/">our Ajaxed shopping cart</a>&quot; to create a one which is very <strong>ideal for designs with limited spaces</strong>.</p>
<h3>The shopping cart will:</h3>
<ul>
<li>be hidden at the top of the page that can be displayed with a show/hide link</li>
<li>open when an item is added to the basket &amp; auto-close</li>
<li>require a manual &quot;hide&quot; click if opened manually</li>
<li>enable us to delete products</li>
</ul>
<p><img height="176" width="480" src="http://www.webresourcesdepot.com/wp-content/uploads/image/ajax-sliding-cart.gif" alt="Ajaxed Sliding Shopping Cart" /></p>
<p><a target="_blank" href="http://webresourcesdepot.com/wp-content/uploads/file/jbasket/sliding-basket/"><img height="48" width="480" src="http://www.webresourcesdepot.com/wp-content/uploads/image/demo-button.gif" alt="Ajaxed Sliding Shopping Cart With jQuery Demo" style="border: 0px none ;" /></a><a target="_blank" href="http://feeds2.feedburner.com/webresourcesdepot"><img src="http://www.webresourcesdepot.com/wp-content/uploads/image/download-button.gif" alt="Ajaxed Sliding Shopping Cart With jQuery Download" style="border: 0px none ;" /></a></p>
<p><span id="more-1084"></span></p>
<div class="featured">
<h3>Sponsors Of E-Commerce Week:</h3>
<p><a target="_blank" href="http://www.sslmatic.com/"><img height="60" width="468" style="border: 0px none ; padding: 0px;" alt="SSLmatic - Cheap SSL Certificates" src="http://www.webresourcesdepot.com/wp-content/uploads/image/sslmatic-468x60.jpg" /></a></p>
</div>
<h3>The HTML</h3>
<p><strong>For The Sliding Basket:</strong></p>
<pre class="brush: php">
&lt;div id=&quot;slidingTopWrap&quot;&gt;
	&lt;div id=&quot;slidingTopContent&quot;&gt;
		&lt;div id=&quot;basketWrap&quot;&gt;
			&lt;div id=&quot;basketTitleWrap&quot;&gt;
				Your Basket &lt;span id=&quot;notificationsLoader&quot;&gt;&lt;/span&gt;
			&lt;/div&gt;
			&lt;div id=&quot;basketItemsWrap&quot;&gt;
				&lt;ul&gt;
				&lt;li&gt;&lt;/li&gt;
				&lt;?php getBasket(); ?&gt;
				&lt;/ul&gt;
			&lt;/div&gt;
		&lt;/div&gt;
	&lt;/div&gt;
	&lt;div id=&quot;slidingTopFooter&quot;&gt;
		&lt;div id=&quot;slidingTopFooterLeft&quot;&gt;
			&lt;img src=&quot;images/arrow-down.png&quot; alt=&quot;Show Basket&quot; /&gt; &lt;a href=&quot;no-js.htm&quot; onclick=&quot;return false;&quot; id=&quot;slidingTopTrigger&quot;&gt;Show Basket&lt;/a&gt;
		&lt;/div&gt;
	&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>The Highlights</p>
<ul>
<li>the div <code>slidingTopWrap</code> is positioned absolutely with top: 0 CSS value to stick to the top of the page</li>
<li>the div <code>slidingTopContent</code> is hided via JavaScript when the page loads &amp; it is actually the part which slides</li>
<li>the div <code>basketWrap</code>, nothing unusual, wraps the contents of the basket</li>
</ul>
<h3>The JavaScript (jQuery)</h3>
<p><strong>Manual Show/Hide Part</strong></p>
<pre class="brush: javascript">
$(&quot;#slidingTopContent&quot;).hide();

$(&quot;#slidingTopTrigger&quot;).live(&quot;click&quot;, function(event) {
	$(&quot;#slidingTopContent&quot;).slideToggle(&quot;slow&quot;, function(){
		if ($(&quot;#slidingTopContent&quot;).is(&quot;:visible&quot;)) {
			$(&quot;#slidingTopFooterLeft&quot;).html(&#039;&lt;img src=&quot;images/arrow-up.png&quot; alt=&quot;Hide Basket&quot; /&gt; &lt;a href=&quot;no-js.htm&quot; onclick=&quot;return false;&quot; id=&quot;slidingTopTrigger&quot;&gt;Hide Basket&lt;/a&gt;&#039;);
		} else {
			$(&quot;#slidingTopFooterLeft&quot;).html(&#039;&lt;img src=&quot;images/arrow-down.png&quot; alt=&quot;Show Basket&quot; /&gt; &lt;a href=&quot;no-js.htm&quot; onclick=&quot;return false;&quot; id=&quot;slidingTopTrigger&quot;&gt;Show Basket&lt;/a&gt;&#039;);
		}
	});
}); 
</pre>
<p>The Highlights:</p>
<ul>
<li>we have <code>$(&quot;#slidingTopContent&quot;).hide();</code> in the beginning to hide the div in the initial load</li>
<li>when the #slidingTopTrigger is clicked, we use the <code>slideToggle</code> function to show/hide the #slidingTopContent. To understand whether it is open or not, we have an if then else clause as <code>if ($(&quot;#slidingTopContent&quot;).is(&quot;:visible&quot;)) {</code>
<ul>
<li>if the #slidingTopContent is visible, we insert the &quot;hide HTML&quot;</li>
<li>if the #slidingTopContent is <strong>not</strong> visible, we insert the &quot;show HTML&quot;</li>
</ul>
</li>
<li>you&#8217;ll see that we used the <code>$(&quot;#slidingTopTrigger&quot;).live(&quot;click&quot;, function(event) {</code> rather than a standard click function. The reason is adding the new created HTMLs to the DOM</li>
</ul>
<p><strong>Adding Products</strong></p>
<pre class="brush: javascript">
$(&quot;.productPriceWrapRight a img&quot;).click(function() {
	var productIDValSplitter 	= (this.id).split(&quot;_&quot;);
	var productIDVal 			= productIDValSplitter[1];

	if ($(&quot;#slidingTopContent&quot;).is(&quot;:visible&quot;)) {

		$(&quot;#notificationsLoader&quot;).html(&#039;&lt;img src=&quot;images/loader.gif&quot;&gt;&#039;);

		$.ajax({
		type: &quot;POST&quot;,
		url: &quot;inc/functions.php&quot;,
		data: { productID: productIDVal, action: &quot;addToBasket&quot;},
		success: function(theResponse) {

		if( $(&quot;#productID_&quot; + productIDVal).length &gt; 0){
			$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 0 }, 500);
			$(&quot;#productID_&quot; + productIDVal).before(theResponse).remove();
			$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 0 }, 500);
			$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 1 }, 500);
			$(&quot;#notificationsLoader&quot;).empty();

		} else {
			$(&quot;#basketItemsWrap li:first&quot;).before(theResponse);
			$(&quot;#basketItemsWrap li:first&quot;).hide();
			$(&quot;#basketItemsWrap li:first&quot;).show(&quot;slow&quot;);
			$(&quot;#notificationsLoader&quot;).empty();
		}

		}
		}); 

	} else {

		$(&quot;#slidingTopContent&quot;).slideToggle(&quot;slow&quot;, function(){		

			$(&quot;#slidingTopFooterLeft&quot;).html(&#039;&lt;img src=&quot;images/arrow-up.png&quot; alt=&quot;Hide Basket&quot; /&gt; &lt;a href=&quot;aaa.htm&quot; onclick=&quot;return false;&quot; id=&quot;slidingTopTrigger&quot;&gt;Hide Basket&lt;/a&gt;&#039;);
			$(&quot;#notificationsLoader&quot;).html(&#039;&lt;img src=&quot;images/loader.gif&quot;&gt;&#039;);

			$.ajax({
			type: &quot;POST&quot;,
			url: &quot;inc/functions.php&quot;,
			data: { productID: productIDVal, action: &quot;addToBasket&quot;},
			success: function(theResponse) {

			if( $(&quot;#productID_&quot; + productIDVal).length &gt; 0){
				$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 0 }, 500);
				$(&quot;#productID_&quot; + productIDVal).before(theResponse).remove();
				$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 0 }, 500);
				$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 1 }, 500);
				$(&quot;#notificationsLoader&quot;).empty();

			} else {
				$(&quot;#basketItemsWrap li:first&quot;).before(theResponse);
				$(&quot;#basketItemsWrap li:first&quot;).hide();
				$(&quot;#basketItemsWrap li:first&quot;).show(&quot;slow&quot;);
				$(&quot;#notificationsLoader&quot;).empty();
			}

			}
			}); 

			$(&quot;#slidingTopTrigger&quot;).fadeTo(4000, 1, function(){
				$(&quot;#slidingTopContent&quot;).slideToggle(&quot;slow&quot;, function(){
					$(&quot;#slidingTopFooterLeft&quot;).html(&#039;&lt;img src=&quot;images/arrow-down.png&quot; alt=&quot;Show Basket&quot; /&gt; &lt;a href=&quot;aaa.htm&quot; onclick=&quot;return false;&quot; id=&quot;slidingTopTrigger&quot;&gt;Show Basket&lt;/a&gt;&#039;);
				});

			});

		});
	}

});
</pre>
<p>The Highlights:</p>
<p>As &quot;how-to&quot; on sending the Ajax query &amp; fading animations are described in the <a href="http://www.webresourcesdepot.com/creating-a-slick-ajaxed-add-to-basket-with-jquery-and-php/">previous post</a>, we won&#8217;t repeating the same info here &amp; focus on the effects.</p>
<ul>
<li>we again run the same if-then-else clause
<ul>
<li>if the #slidingTopContent is open send an Ajax query to functions.php and add-the-products to basket</li>
<li>if the #slidingTopContent is closed:
<ul>
<li>slideToggle the div</li>
<li>insert the &quot;hide HTML&quot; to #slidingTopFooterLeft&quot;</li>
<li>send an Ajax query to functions.php and add-the-products to basket</li>
<li>wait for x seconds:&nbsp;<code>$(&quot;#slidingTopTrigger&quot;).fadeTo(4000, 1, function(){</code></li>
<li>slideToggle the div</li>
<li>insert the &quot;show HTML&quot; to #slidingTopFooterLeft&quot;</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><strong>P.S.</strong> To make the example work on your side, you should be creating a new database with the jBasket.sql file inside the download package &amp; configure the database connection information inside &ldquo;inc/db.php&rdquo; file.</p>
<p><strong>Special Downloads:</strong><br />
<a href="http://www.webresourcesdepot.com/?download=jBasket" target="_blank">Ajaxed Add-To-Basket Scenarios With jQuery And PHP</a><br />
<a href="http://www.webresourcesdepot.com/?download=Free-Admin-Template" target="_blank">Free Admin Template For Web Applications</a><br />
<a href="http://www.webresourcesdepot.com/?download=jQuery-Dynamic-Drag-Drop" target="_blank">jQuery Dynamic Drag&#8217;n Drop</a><br />
<a href="http://www.webresourcesdepot.com/?download=sTwitter-1-0" target="_blank">ScheduledTweets</a></p>
<p><strong>Advertisements:</strong><br />
<a href="http://www.admintemplates.com" target="_blank">Professional XHTML Admin Template ($15 Discount With The Code: WRD.)</a><br />
<a href="http://www.xhtmchop.com" target="_blank">Psd to Xhtml</a><br />
<a href="http://www.sslmatic.com" target="_blank">SSLmatic &#8211; Cheap SSL Certificates (from $19.99/year)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webresourcesdepot.com/ajaxed-sliding-shopping-cart-with-jquery/feed/</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
		<item>
		<title>Fly-To-Basket Effect With jQuery</title>
		<link>http://www.webresourcesdepot.com/fly-to-basket-effect-with-jquery/</link>
		<comments>http://www.webresourcesdepot.com/fly-to-basket-effect-with-jquery/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 07:52:37 +0000</pubDate>
		<dc:creator>Umut M.</dc:creator>
				<category><![CDATA[E-Commerce]]></category>
		<category><![CDATA[Extras]]></category>
		<category><![CDATA[MIT License]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.webresourcesdepot.com/?p=1080</guid>
		<description><![CDATA[<p><a href='http://rss.buysellads.com/click.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=1080&c=16129' target='_blank'><img src='http://rss.buysellads.com/img.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=1080&c=16129' border='0' alt='' /></a></p><p><a href='http://buysellads.com/buy/sitedetails/pubkey/ed230295611f656daf3115e6d682ca7d/zone/1259982' target='_blank'>Advertise here with BSA</a></p><br />In this 3rd day of the &#34;WRD E-Commerce Week&#34;, we will be adding a chic fly-to-basket effect to our previously created Ajaxed shopping cart using jQuery. Rather than the complete HTML structure &#38; PHP code that adds/removes the products, we&#8217;ll be focusing on the details related with&#160; the effect. To findout the details of the [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://rss.buysellads.com/click.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=1080&c=17247' target='_blank'><img src='http://rss.buysellads.com/img.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=1080&c=17247' border='0' alt='' /></a></p><p><a href='http://buysellads.com/buy/sitedetails/pubkey/ed230295611f656daf3115e6d682ca7d/zone/1259982' target='_blank'>Advertise here with BSA</a></p><br /><p>In this 3rd day of the &quot;<a href="http://www.webresourcesdepot.com/e-commerce-week-at-webresourcesdepot-want-to-sponsor/">WRD E-Commerce Week</a>&quot;, we will be adding a chic <strong>fly-to-basket effect</strong> to our <a href="http://www.webresourcesdepot.com/creating-a-slick-ajaxed-add-to-basket-with-jquery-and-php/">previously created Ajaxed shopping cart</a> using <strong>jQuery</strong>.</p>
<p>Rather than the complete HTML structure &amp; PHP code that adds/removes the products, <strong>we&#8217;ll be focusing on the details related with&nbsp; the effect</strong>.</p>
<p><img height="156" width="480" alt="Fly To Basket With jQuery" src="http://www.webresourcesdepot.com/wp-content/uploads/image/fly-to-basket-jquery.jpg" /></p>
<p>To findout the details of the complete HTML structure &amp; PHP code, please check our post: <a href="http://www.webresourcesdepot.com/creating-a-slick-ajaxed-add-to-basket-with-jquery-and-php/">Creating A Slick Ajaxed Add-To-Basket With jQuery And PHP</a>. And, a full working example can be found in the download package.</p>
<p><a href="http://webresourcesdepot.com/wp-content/uploads/file/jbasket/fly-to-basket/" target="_blank"><img height="48" width="480" style="border: 0px none ;" alt="Fly-To-Basket Effect With jQuery Demo" src="http://www.webresourcesdepot.com/wp-content/uploads/image/demo-button.gif" /></a><a href="http://feeds2.feedburner.com/webresourcesdepot" target="_blank"><img style="border: 0px none ;" alt="Fly-To-Basket Effect With jQuery Download" src="http://www.webresourcesdepot.com/wp-content/uploads/image/download-button.gif" /></a></p>
<p><span id="more-1080"></span></p>
<div class="featured">
<h3>Sponsors Of E-Commerce Week:</h3>
<p><a href="http://www.sslmatic.com/" target="_blank"><img width="468" height="60" src="http://www.webresourcesdepot.com/wp-content/uploads/image/sslmatic-468x60.jpg" alt="SSLmatic - Cheap SSL Certificates" style="border: 0px none ; padding: 0px;" /></a></p>
</div>
<h3>The HTML</h3>
<p><strong>HTML For The Product&#8217;s Wrapper:</strong></p>
<pre class="brush: php">
&lt;div class=&quot;productWrap&quot;&gt;
	&lt;div class=&quot;productImageWrap&quot;&gt;
		&lt;img src=&quot;images/product1.jpg&quot; alt=&quot;Product1&quot; /&gt;
	&lt;/div&gt;
	&lt;div class=&quot;productNameWrap&quot;&gt;
		Krups Coffee Maker
	&lt;/div&gt;
	&lt;div class=&quot;productPriceWrap&quot;&gt;
		&lt;div class=&quot;productPriceWrapLeft&quot;&gt;
			$95
		&lt;/div&gt;
		&lt;div class=&quot;productPriceWrapRight&quot;&gt;
			&lt;a href=&quot;inc/functions.php?action=addToBasket&amp;productID=1&quot; onClick=&quot;return false;&quot;&gt;
				&lt;img src=&quot;images/add-to-basket.gif&quot; alt=&quot;Add To Basket&quot; width=&quot;111&quot; height=&quot;32&quot; id=&quot;featuredProduct_1&quot; /&gt;
			&lt;/a&gt;
		&lt;/div&gt;
	&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>The part we&#8217;ll focus is the contents inside <code>&lt;div class=&quot;productPriceWrapRight&quot;&gt;</code> which wraps the &quot;add-to-basket&quot; button.</p>
<p>The Highlights:</p>
<ul>
<li>a link with <code>onClick=&quot;return false;</code> value which means it won&#8217;t be active if JavaScript is active (to make the script unobtrusive)</li>
<li>add-to-basket image has an unique ID: <code>id=&quot;featuredProduct_1&quot;</code> which we&#8217;ll use to understand the button of which product is clicked</li>
</ul>
<p><strong>HTML For The Basket:</strong></p>
<pre class="brush: php">
&lt;div id=&quot;basketWrap&quot;&gt;
	&lt;div id=&quot;basketTitleWrap&quot;&gt;
		Your Basket &lt;span id=&quot;notificationsLoader&quot;&gt;&lt;/span&gt;
	&lt;/div&gt;
	&lt;div id=&quot;basketItemsWrap&quot;&gt;
		&lt;ul&gt;
		&lt;li&gt;&lt;/li&gt;
		&lt;?php getBasket(); ?&gt;
		&lt;/ul&gt;
	&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>The Highlights:</p>
<ul>
<li>we have an empty <code>&lt;span&gt;</code> with <code>id=&quot;notificationsLoader&quot;</code> to show a loading image</li>
<li>we keep an empty div to be able to insert any data before/after them</li>
<li>we call a PHP function: <code>&lt;?php getBasket(); ?&gt;</code> to get the basket data when the page is first loaded.</li>
</ul>
<h3>The JavaScript (jQuery)</h3>
<pre class="brush: javascript">
$(&quot;#basketItemsWrap li:first&quot;).hide();

$(&quot;.productPriceWrapRight a img&quot;).click(function() {
	var productIDValSplitter 	= (this.id).split(&quot;_&quot;);
	var productIDVal 			= productIDValSplitter[1];

	var productX 		= $(&quot;#productImageWrapID_&quot; + productIDVal).offset().left;
	var productY 		= $(&quot;#productImageWrapID_&quot; + productIDVal).offset().top;

	if( $(&quot;#productID_&quot; + productIDVal).length &gt; 0){
		var basketX 		= $(&quot;#productID_&quot; + productIDVal).offset().left;
		var basketY 		= $(&quot;#productID_&quot; + productIDVal).offset().top;
	} else {
		var basketX 		= $(&quot;#basketTitleWrap&quot;).offset().left;
		var basketY 		= $(&quot;#basketTitleWrap&quot;).offset().top;
	}

	var gotoX 			= basketX - productX;
	var gotoY 			= basketY - productY;

	var newImageWidth 	= $(&quot;#productImageWrapID_&quot; + productIDVal).width() / 3;
	var newImageHeight	= $(&quot;#productImageWrapID_&quot; + productIDVal).height() / 3;

	$(&quot;#productImageWrapID_&quot; + productIDVal + &quot; img&quot;)
	.clone()
	.prependTo(&quot;#productImageWrapID_&quot; + productIDVal)
	.css({&#039;position&#039; : &#039;absolute&#039;})
	.animate({opacity: 0.4}, 100 )
	.animate({opacity: 0.1, marginLeft: gotoX, marginTop: gotoY, width: newImageWidth, height: newImageHeight}, 1200, function() {
																																																																												$(this).remove();

		$(&quot;#notificationsLoader&quot;).html(&#039;&lt;img src=&quot;images/loader.gif&quot;&gt;&#039;);

		$.ajax({
		type: &quot;POST&quot;,
		url: &quot;inc/functions.php&quot;,
		data: { productID: productIDVal, action: &quot;addToBasket&quot;},
		success: function(theResponse) {

		if( $(&quot;#productID_&quot; + productIDVal).length &gt; 0){
			$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 0 }, 500);
			$(&quot;#productID_&quot; + productIDVal).before(theResponse).remove();
			$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 0 }, 500);
			$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 1 }, 500);
			$(&quot;#notificationsLoader&quot;).empty();

		} else {
			$(&quot;#basketItemsWrap li:first&quot;).before(theResponse);
			$(&quot;#basketItemsWrap li:first&quot;).hide();
			$(&quot;#basketItemsWrap li:first&quot;).show(&quot;slow&quot;);
			$(&quot;#notificationsLoader&quot;).empty();
		}

		}
		});  

	});

});
</pre>
<p>Highlights:</p>
<ul>
<li><strong>splitting the ID&nbsp;of the clicked &quot;add-to-basket&quot; image</strong> which is &quot;featuredProduct_1&quot; from the &quot;_&quot; character &amp; get the databaseID of the product</li>
<li>using <a target="_blank" href="http://docs.jquery.com/CSS/offset">jQuery&#8217;s offset</a>, we get the current x-y position of the product</li>
<li>run a &quot;if-then-else&quot; clause which:
<ul>
<li><strong>if that product is already in the basket:</strong> <code>if( $(&quot;#productID_&quot; + productIDVal).length &gt; 0){</code> (if an element with that ID exists in the basket), if exists, then we get the x-y positions of that element using &quot;offset&quot; again, so we can target that element while flying our product</li>
<li><strong>if that product isn&#8217;t in the basket:</strong> then we get the x-y positions of a static element in the basket HTMl area (#basketTitleWrap in our case)</li>
</ul>
</li>
<li><strong>very important</strong>:&nbsp;we create 2 variables; gotoX &amp; gotoY by subtracting the element in the basket&#8217;s position from the product&#8217;s position. And we get the distance product needs to animate (fly) in x&#8217;s &amp; y&#8217;s</li>
<li>again create 2 variables named newImageWidth &amp; newImageHeight which are x times (3 in our case) smaller the size of our product&#8217;s image. This is used to create a resizing effect while flying the product to the basket</li>
<li><strong>and, let&#8217;s fly the product</strong>: targeting the product image to be flied;&nbsp;<code>$(&quot;#productImageWrapID_&quot; + productIDVal + &quot; img&quot;)</code>. We clone it with <a target="_blank" href="http://docs.jquery.com/Manipulation/clone">jQuery&#8217;s clone,</a> place inside the same element where the original image exists with <a target="_blank" href="http://docs.jquery.com/Manipulation/prependTo">prependTo</a> &amp; set it&#8217;s position to <code>absolute</code>. The next thing, we decrease its opacity so it starts in a little transparent look before the animation. And, we fly it by mentioning the <code>marginLeft</code> &amp; <code>marginTop</code> values we calculated. At the same time, we make it more transparent &amp; resize it. Also, we set the duration of the animation (1200 in our case).</li>
<li>As a callback function (after the animation ends), we remove the cloned image from the DOM, show the Ajax loader &amp; post a query to our PHP page. That&#8217;s all.</li>
</ul>
<p><strong>P.S.</strong> To make the example work on your side, you should be creating a new database with the jBasket.sql file inside the download package &amp; configure the database connection information inside “inc/db.php” file.</p>
<p><strong>Special Downloads:</strong><br />
<a href="http://www.webresourcesdepot.com/?download=jBasket" target="_blank">Ajaxed Add-To-Basket Scenarios With jQuery And PHP</a><br />
<a href="http://www.webresourcesdepot.com/?download=Free-Admin-Template" target="_blank">Free Admin Template For Web Applications</a><br />
<a href="http://www.webresourcesdepot.com/?download=jQuery-Dynamic-Drag-Drop" target="_blank">jQuery Dynamic Drag&#8217;n Drop</a><br />
<a href="http://www.webresourcesdepot.com/?download=sTwitter-1-0" target="_blank">ScheduledTweets</a></p>
<p><strong>Advertisements:</strong><br />
<a href="http://www.admintemplates.com" target="_blank">Professional XHTML Admin Template ($15 Discount With The Code: WRD.)</a><br />
<a href="http://www.xhtmchop.com" target="_blank">Psd to Xhtml</a><br />
<a href="http://www.sslmatic.com" target="_blank">SSLmatic &#8211; Cheap SSL Certificates (from $19.99/year)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webresourcesdepot.com/fly-to-basket-effect-with-jquery/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>Creating A Slick Ajaxed Add-To-Basket With jQuery And PHP</title>
		<link>http://www.webresourcesdepot.com/creating-a-slick-ajaxed-add-to-basket-with-jquery-and-php/</link>
		<comments>http://www.webresourcesdepot.com/creating-a-slick-ajaxed-add-to-basket-with-jquery-and-php/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 07:05:40 +0000</pubDate>
		<dc:creator>Umut M.</dc:creator>
				<category><![CDATA[E-Commerce]]></category>
		<category><![CDATA[Extras]]></category>
		<category><![CDATA[MIT License]]></category>
		<category><![CDATA[No License]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Mysql]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.webresourcesdepot.com/?p=1071</guid>
		<description><![CDATA[<p><a href='http://rss.buysellads.com/click.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=1071&c=28098' target='_blank'><img src='http://rss.buysellads.com/img.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=1071&c=28098' border='0' alt='' /></a></p><p><a href='http://buysellads.com/buy/sitedetails/pubkey/ed230295611f656daf3115e6d682ca7d/zone/1259982' target='_blank'>Advertise here with BSA</a></p><br />It is a clear fact that Ajaxed interfaces, if not overused, eases using websites so much. For an e-commerce website, this can mean a better shopping experience for customers where they can concentrate more on the products which may result in better sales. This is a detailed tutorial which shows creating an unobtrusive Ajaxed shopping [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://rss.buysellads.com/click.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=1071&c=19032' target='_blank'><img src='http://rss.buysellads.com/img.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=1071&c=19032' border='0' alt='' /></a></p><p><a href='http://buysellads.com/buy/sitedetails/pubkey/ed230295611f656daf3115e6d682ca7d/zone/1259982' target='_blank'>Advertise here with BSA</a></p><br /><p>It is a clear fact that Ajaxed interfaces, if not overused, eases using websites so much.</p>
<p>For an e-commerce website, this can mean <strong>a better shopping experience for customers</strong> where they can concentrate more on the products which may result in better sales.</p>
<p><img width="480" height="160" alt="jQuery Ajax Shopping Cart" src="http://www.webresourcesdepot.com/wp-content/uploads/image/jquery-ajax-shopping-cart.jpg" /></p>
<p>This is a detailed tutorial which shows creating an <strong>unobtrusive Ajaxed shopping cart using <strong>jQuery</strong> &amp; <strong>PHP</strong> </strong>and can guide you to Ajaxify any e-commerce software you may already be using or coding.</p>
<p>The main functions of the cart will be adding/removing items to the basket without the need of refreshing the page &amp; displaying the actions with effects.</p>
<h3>Other Add-To-Basket Tutorials Built on This Example:</h3>
<ul>
<li><a href="http://www.webresourcesdepot.com/fly-to-basket-effect-with-jquery/">Fly-To-Basket Effect With jQuery</a></li>
<li><a href="http://www.webresourcesdepot.com/ajaxed-sliding-shopping-cart-with-jquery/">Ajaxed Sliding Shopping Cart With jQuery</a></li>
</ul>
<p> <span id="more-1071"></span>
<p>To try the demo or download the script:</p>
<p><a target="_blank" href="http://webresourcesdepot.com/wp-content/uploads/file/jbasket/standard/"><img width="480" height="48" src="http://www.webresourcesdepot.com/wp-content/uploads/image/demo-button.gif" alt="Slick Add-To-Basket With jQuery And PHP Demo" style="border: 0px none ;" /></a><a target="_blank" href="http://feeds2.feedburner.com/webresourcesdepot"><img src="http://www.webresourcesdepot.com/wp-content/uploads/image/download-button.gif" alt="Slick Add-To-Basket With jQuery And PHP Download" style="border: 0px none ;" /></a></p>
<div class="featured">
<h3>Sponsors Of E-Commerce Week:</h3>
<p> <a href="http://www.sslmatic.com/" target="_blank"><img width="468" height="60" src="http://www.webresourcesdepot.com/wp-content/uploads/image/sslmatic-468x60.jpg" alt="SSLmatic - Cheap SSL Certificates" style="border: 0px none ; padding: 0px;" /></a></div>
<h3>The HTML</h3>
<p>Rather than the formatting of the page, as you can design it however you prefer, we&#8217;ll be focusing on the vital parts which does all the tricks.</p>
<p><strong>HTML For The Product&#8217;s Wrapper:</strong></p>
<pre class="brush: php"> &lt;div class=&quot;productWrap&quot;&gt; &lt;div class=&quot;productImageWrap&quot;&gt; &lt;img src=&quot;images/product1.jpg&quot; alt=&quot;Product1&quot; /&gt; &lt;/div&gt; &lt;div class=&quot;productNameWrap&quot;&gt; Krups Coffee Maker &lt;/div&gt; &lt;div class=&quot;productPriceWrap&quot;&gt; &lt;div class=&quot;productPriceWrapLeft&quot;&gt; $95 &lt;/div&gt; &lt;div class=&quot;productPriceWrapRight&quot;&gt; &lt;a href=&quot;inc/functions.php?action=addToBasket&amp;productID=1&quot; onClick=&quot;return false;&quot;&gt; &lt;img src=&quot;images/add-to-basket.gif&quot; alt=&quot;Add To Basket&quot; width=&quot;111&quot; height=&quot;32&quot; id=&quot;featuredProduct_1&quot; /&gt; &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </pre>
<p>The part we&#8217;ll focus is the contents inside <code>&lt;div class=&quot;productPriceWrapRight&quot;&gt;</code> which wraps the &quot;add-to-basket&quot; button.</p>
<p>The Highlights:</p>
<ul>
<li>a link with <code>onClick=&quot;return false;</code> value which means it won&#8217;t be active if JavaScript is active (to make the script unobtrusive)</li>
<li>add-to-basket image has an unique ID: <code>id=&quot;featuredProduct_1&quot;</code> which we&#8217;ll use to understand the button of which product is clicked</li>
</ul>
<p><strong>HTML For The Basket:</strong></p>
<pre class="brush: php"> &lt;div id=&quot;basketWrap&quot;&gt; &lt;div id=&quot;basketTitleWrap&quot;&gt; Your Basket &lt;span id=&quot;notificationsLoader&quot;&gt;&lt;/span&gt; &lt;/div&gt; &lt;div id=&quot;basketItemsWrap&quot;&gt; &lt;ul&gt; &lt;li&gt;&lt;/li&gt; &lt;?php getBasket(); ?&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; </pre>
<p>The Highlights:</p>
<ul>
<li>we have an empty <code>&lt;span&gt;</code> with <code>id=&quot;notificationsLoader&quot;</code> to show a loading image</li>
<li>we keep an empty div to be able to insert any data before/after them</li>
<li>we call a PHP function: <code>&lt;?php getBasket(); ?&gt;</code> to get the basket data when the page is first loaded.</li>
</ul>
<h3>The JavaScript (jQuery)</h3>
<p>We have 2 main jQuery functions:</p>
<p><strong>Function For Adding To Basket:</strong></p>
<pre class="brush: javascript"> $(&quot;.productPriceWrapRight a img&quot;).click(function() { var productIDValSplitter = (this.id).split(&quot;_&quot;); var productIDVal = productIDValSplitter[1]; $(&quot;#notificationsLoader&quot;).html(&#039;&lt;img src=&quot;images/loader.gif&quot;&gt;&#039;); $.ajax({ type: &quot;POST&quot;, url: &quot;inc/functions.php&quot;, data: { productID: productIDVal, action: &quot;addToBasket&quot;}, success: function(theResponse) { if( $(&quot;#productID_&quot; + productIDVal).length &gt; 0){ $(&quot;#productID_&quot; + productIDVal).animate({ opacity: 0 }, 500, function() { $(&quot;#productID_&quot; + productIDVal).before(theResponse).remove(); }); $(&quot;#productID_&quot; + productIDVal).animate({ opacity: 0 }, 500); $(&quot;#productID_&quot; + productIDVal).animate({ opacity: 1 }, 500); $(&quot;#notificationsLoader&quot;).empty(); } else { $(&quot;#basketItemsWrap li:first&quot;).before(theResponse); $(&quot;#basketItemsWrap li:first&quot;).hide(); $(&quot;#basketItemsWrap li:first&quot;).show(&quot;slow&quot;); $(&quot;#notificationsLoader&quot;).empty(); } } }); }); </pre>
<p>The Highlights:</p>
<ul>
<li><strong>splitting the ID&nbsp;of the clicked &quot;add-to-basket&quot; image</strong> which is &quot;featuredProduct_1&quot; from the &quot;_&quot; character &amp; get the databaseID of the product (1)</li>
<li>inserting the <code>loader.gif</code>image inside the element with <code>id=&quot;notificationsLoader&quot;</code></li>
<li>posting a data with Ajax to our functions.php fil which handles all the server-side jobs. 2 data are posted: <code>productID</code> and the action to be done which is <code>addToBasket</code></li>
<li>There are 2 possibilities when the data is posted, the items may already be inside the basket or it may be a new item. So, we have an if clause: <code>if( $(&quot;#productID_&quot; + productIDVal).length &gt; 0){</code> which checks if an element with ID: productID<strong>1</strong> (1 is a variable) exists in the page
<ul>
<li>&nbsp;if it exist:
<ul>
<li>we change the opacity of that object to 0 (make it invisible)</li>
<li>load the new <code>&lt;li&gt;product info&lt;/li&gt;</code> response that comes from the functions.php</li>
<li>remove the original <code>&lt;li&gt;product info&lt;/li&gt;</code> object whose opacity was 0</li>
<li>and play with the new <code>&lt;li&gt;product info&lt;/li&gt;</code> object&#8217;s opacity to create a blinking effect</li>
<li>empty the contents inside<code> id=&quot;notificationsLoader&quot;</code> to stop the loading animation</li>
</ul>
</li>
<li>if it does not exist:<br /> 
<ul>
<li>we insert the response from the functions.php before the first hidden &lt;li&gt; and hide it</li>
<li>then use <strong>jQuery&#8217;s show function</strong> to display it with an effect</li>
<li>empty the contents inside<code> id=&quot;notificationsLoader&quot;</code> to stop the loading animation</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><strong>Function For Removing From Basket:</strong></p>
<pre class="brush: javascript"> $(&quot;#basketItemsWrap li img&quot;).live(&quot;click&quot;, function(event) { var productIDValSplitter = (this.id).split(&quot;_&quot;); var productIDVal = productIDValSplitter[1]; $(&quot;#notificationsLoader&quot;).html(&#039;&lt;img src=&quot;images/loader.gif&quot;&gt;&#039;); $.ajax({ type: &quot;POST&quot;, url: &quot;inc/functions.php&quot;, data: { productID: productIDVal, action: &quot;deleteFromBasket&quot;}, success: function(theResponse) { $(&quot;#productID_&quot; + productIDVal).hide(&quot;slow&quot;, function() {$(this).remove();}); $(&quot;#notificationsLoader&quot;).empty(); } }); }); </pre>
<p>The Highlights:</p>
<ul>
<li>As the objects are inserted to basket via Ajax, the new HTML items inside the basket are normally not loaded to the DOM and we can&#8217;t reach them via JavaScript. <strong>jQuery offers an event named &quot;live&quot;</strong> (starting from jQuery 1.3) which loads the new created items to the DOM. So we used this event.</li>
<li>All other tasks are similar to adding an item, we splitted the HTML element from the &quot;_&quot; character and got the <code>productID</code> to be deleted and sent it to functions.php via Ajax.</li>
</ul>
<h3>The Database</h3>
<p>We have used a MySQL database in this example with 2 tables:</p>
<p><strong>Products</strong>:</p>
<p><img width="480" height="90" src="http://www.webresourcesdepot.com/wp-content/uploads/image/add-to-basket-db-table2.jpg" alt="Add To Basket Products Table" /></p>
<p><strong>Baskets</strong> (for keeping the shopping cart of every different session)</p>
<p><img width="480" height="90" src="http://www.webresourcesdepot.com/wp-content/uploads/image/add-to-basket-db-table1.jpg" alt="Add To Basket Sessions Table" /></p>
<h3>The PHP</h3>
<p>There is nothing complicated on the PHP part.</p>
<p><strong>Handle The Variables:</strong></p>
<pre class="brush: php"> session_start(); $sessionID = $_COOKIE[&#039;PHPSESSID&#039;]; if($_POST[&#039;action&#039;] != &#039;&#039; || $_GET[&#039;action&#039;] != &#039;&#039;) { if($_POST[&#039;action&#039;] == &#039;&#039;) { $action = $_GET[&#039;action&#039;]; $productID = $_GET[&#039;productID&#039;]; $noJavaScript = 1; } else { $action = $_POST[&#039;action&#039;]; $productID = $_POST[&#039;productID&#039;]; $noJavaScript = 0; } } </pre>
<p>The Highlights:</p>
<ul>
<li>we <strong>create a session variable</strong> so every different user will have their own baskets</li>
<li>understand if the request comes from a POST (Ajax) or GET (JS disabled) request and get the <code>action</code> &amp; <code>productID</code> variables</li>
<li>if it is a GET request we change the value of a variable named <code>$noJavaScript</code> to 1</li>
</ul>
<p><strong>PHP For Add To Basket:</strong></p>
<pre class="brush: php"> if ($action == &quot;addToBasket&quot;){ $productInBasket = 0; $productTotalPrice = 0; $query = &quot;SELECT * FROM products WHERE productID = &quot; . $productID; $result = mysql_query($query); $row = mysql_fetch_array( $result ); $productPrice = $row[&#039;productPrice&#039;]; $productName = $row[&#039;productName&#039;]; $query = &quot;INSERT INTO baskets (productID, productPrice, basketSession) VALUES (&#039;$productID&#039;, &#039;$productPrice&#039;, &#039;$sessionID&#039;)&quot;; mysql_query($query) or die(&#039;Error, insert query failed&#039;); $query = &quot;SELECT * FROM baskets WHERE productID = &quot; . $productID . &quot; AND basketSession = &#039;&quot; . $sessionID . &quot;&#039;&quot;; $result = mysql_query($query) or die(mysql_error());; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $totalItems = $totalItems + 1; $productTotalPrice = $productTotalPrice + $row[&#039;productPrice&#039;]; } if ($noJavaScript == 1) { header(&quot;Location: ../index.php&quot;); } else { echo (&#039;&lt;li id=&quot;productID_&#039; . $productID . &#039;&quot;&gt;&lt;a href=&quot;inc/functions.php?action=deleteFromBasket&amp;productID=&#039; . $productID . &#039;&quot; onClick=&quot;return false;&quot;&gt;&lt;img src=&quot;images/delete.png&quot; id=&quot;deleteProductID_&#039; . $productID . &#039;&quot;&gt;&lt;/a&gt; &#039; . $productName . &#039;(&#039; . $totalItems . &#039; items) - $&#039; . $productTotalPrice . &#039;&lt;/li&gt;&#039;); } } </pre>
<p>The Highlights:</p>
<ul>
<li>we insert the product to the database. If <code>$noJavaScript</code> to 1 we redirect to the index.php else <strong>we create a &lt;li&gt; element</strong> including the product&#8217;s details &amp; <strong><code>echo</code> it so we can insert it via jQuery</strong>.</li>
</ul>
<p><strong>PHP For Delete From Basket:</strong></p>
<pre class="brush: php"> if ($action == &quot;deleteFromBasket&quot;){ $query = &quot;DELETE FROM baskets WHERE productID = &quot; . $productID . &quot; AND basketSession = &#039;&quot; . $sessionID . &quot;&#039;&quot;; mysql_query($query) or die(&#039;Error, delete query failed&#039;); if ($noJavaScript == 1) { header(&quot;Location: ../index.php&quot;); } } </pre>
<p>The Highlights:</p>
<ul>
<li>we delete the product to the database. If <code>$noJavaScript</code> to 1 we redirect to the index.php</li>
</ul>
<p><strong>PHP For Getting The Basket (For Initial Load)</strong></p>
<p>Like mentioned before, we create a function to get the basket&#8217;s current situation, so it can be loaded in the initial loading of the page.</p>
<pre class="brush: php"> function getBasket(){ session_start(); $sessionID = $_COOKIE[&#039;PHPSESSID&#039;]; $query = &quot;SELECT * FROM baskets WHERE basketSession = &#039;&quot; . $sessionID . &quot;&#039; GROUP BY productID ORDER By basketID DESC&quot;; $result = mysql_query($query); //echo $query; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $query2 = &quot;SELECT * FROM products WHERE productID = &quot; . $row[&#039;productID&#039;]; $result2 = mysql_query($query2); $row2 = mysql_fetch_array( $result2 ); $productID = $row2[&#039;productID&#039;]; $productPrice = $row2[&#039;productPrice&#039;]; $productName = $row2[&#039;productName&#039;]; $query2 = &quot;SELECT COUNT(*) AS totalItems FROM baskets WHERE basketSession = &#039;&quot; . $sessionID . &quot;&#039; AND productID = &quot; . $productID; $result2 = mysql_query($query2); $row2 = mysql_fetch_array( $result2 ); $totalItems = $row2[&#039;totalItems&#039;]; $basketText = $basketText . &#039;&lt;li id=&quot;productID_&#039; . $productID . &#039;&quot;&gt;&lt;a href=inc/functions.php?action=deleteFromBasket&amp;productID=&#039; . $productID . &#039; onClick=&quot;return false;&quot;&gt;&lt;img src=&quot;images/delete.png&quot; id=&quot;deleteProductID_&#039; . $productID . &#039;&quot;&gt;&lt;/a&gt; &#039; . $productName . &#039;(&#039; . $totalItems . &#039; items) - $&#039; . ($totalItems * $productPrice) . &#039;&lt;/li&gt;&#039;; } echo $basketText; } </pre>
<p>The Highlights:</p>
<ul>
<li>This is a standard PHP function which creates the HTML for the items in the basket with a loop</li>
</ul>
<p>And, the <strong>Ajaxed basket built with jQuery &amp; PHP</strong> is ready-to-use.</p>
<p><strong>P.S.</strong> To make the example work on your side, you should be creating a new database with the jBasket.sql file inside the download package &#038; configure the database connection information inside &#8220;inc/db.php&#8221; file.</p>
<p><strong>Special Downloads:</strong><br />
<a href="http://www.webresourcesdepot.com/?download=jBasket" target="_blank">Ajaxed Add-To-Basket Scenarios With jQuery And PHP</a><br />
<a href="http://www.webresourcesdepot.com/?download=Free-Admin-Template" target="_blank">Free Admin Template For Web Applications</a><br />
<a href="http://www.webresourcesdepot.com/?download=jQuery-Dynamic-Drag-Drop" target="_blank">jQuery Dynamic Drag&#8217;n Drop</a><br />
<a href="http://www.webresourcesdepot.com/?download=sTwitter-1-0" target="_blank">ScheduledTweets</a></p>
<p><strong>Advertisements:</strong><br />
<a href="http://www.admintemplates.com" target="_blank">Professional XHTML Admin Template ($15 Discount With The Code: WRD.)</a><br />
<a href="http://www.xhtmchop.com" target="_blank">Psd to Xhtml</a><br />
<a href="http://www.sslmatic.com" target="_blank">SSLmatic &#8211; Cheap SSL Certificates (from $19.99/year)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webresourcesdepot.com/creating-a-slick-ajaxed-add-to-basket-with-jquery-and-php/feed/</wfw:commentRss>
		<slash:comments>58</slash:comments>
		</item>
		<item>
		<title>jQuery Plugin Development &#8211; 10 Tutorials To Get Started</title>
		<link>http://www.webresourcesdepot.com/jquery-plugin-development-10-tutorials-to-get-started/</link>
		<comments>http://www.webresourcesdepot.com/jquery-plugin-development-10-tutorials-to-get-started/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 06:46:26 +0000</pubDate>
		<dc:creator>Umut M.</dc:creator>
				<category><![CDATA[Extras]]></category>
		<category><![CDATA[Other License]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.webresourcesdepot.com/?p=848</guid>
		<description><![CDATA[<p><a href='http://rss.buysellads.com/click.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=848&c=23240' target='_blank'><img src='http://rss.buysellads.com/img.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=848&c=23240' border='0' alt='' /></a></p><p><a href='http://buysellads.com/buy/sitedetails/pubkey/ed230295611f656daf3115e6d682ca7d/zone/1259982' target='_blank'>Advertise here with BSA</a></p><br />jQuery, one of the most popular JavaScript library, has a huge selection of plugins which makes it more powerful. On the other hand, there are much more codes/modules, from simple alert functions to complex galleries/form validation methods, that are hard-coded inside websites &#38; not converted to plugins. For sure, not every code must become a [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://rss.buysellads.com/click.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=848&c=19092' target='_blank'><img src='http://rss.buysellads.com/img.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=848&c=19092' border='0' alt='' /></a></p><p><a href='http://buysellads.com/buy/sitedetails/pubkey/ed230295611f656daf3115e6d682ca7d/zone/1259982' target='_blank'>Advertise here with BSA</a></p><br /><p><strong><img align="left" alt="jQuery Logo" height="78" src="http://www.webresourcesdepot.com/wp-content/uploads/image/jquery-logo.gif" style="margin-right: 5px;" width="140" />jQuery</strong>, one of the most popular JavaScript library, has a <a href="http://plugins.jquery.com/" target="_blank">huge selection of plugins</a> which makes it more powerful.</p>
<p>On the other hand, there are much more codes/modules, <strong>from simple alert functions to complex galleries/form validation methods</strong>, that are hard-coded inside websites &amp; not converted to plugins.</p>
<p>For sure, <strong>not every code must become a plugin</strong>, that would be meaningless. But converting the ones to be re-used will save a lot of re-development time &amp; if shared with the community, will make the code itself better.</p>
<p><strong>jQuery</strong> offers an easy to learn &amp; flexible environment for <strong>creating plugins</strong>. Here are <strong>10 tutorials to get you started</strong>:</p>
<div class="featured"><strong>You may also like:</strong> <a href="http://www.webresourcesdepot.com/9-free-and-open-source-bug-tracking-softwares/">9 Free And Open Source Bug Tracking Softwares</a>.</div>
<p>&nbsp;</p>
<h3><a href="http://james.padolsey.com/javascript/why-create-a-jquery-plugin/" target="_blank">Why Create A jQuery Plugin?</a></h3>
<p><a href="http://james.padolsey.com/javascript/why-create-a-jquery-plugin/" target="_blank"><img alt="Why Create A jQuery Plugin" height="128" src="http://www.webresourcesdepot.com/wp-content/uploads/image/create-a-jquery-plugin.gif" width="480" /></a></p>
<p>James Padolsey discusses the need &amp; reasons for <strong>creating a jQuery plugin</strong>.</p>
<p>He clearly puts of the advantages provided like portability, time to be gained &amp; more.&nbsp;</p>
<h3><a href="http://docs.jquery.com/Plugins/Authoring" target="_blank">Plugins/Authoring From jQuery.com</a></h3>
<p><a href="http://docs.jquery.com/Plugins/Authoring" target="_blank"><img alt="jQuery Plugin Tutorial" height="128" src="http://www.webresourcesdepot.com/wp-content/uploads/image/jquery-plugin-tutorial.gif" width="480" /></a></p>
<p>The first stop for everyone planning to <strong>create a jQuery plugin</strong>.</p>
<p>It covers the logic, naming patterns &amp; steps like:</p>
<ul>
<li class="toclevel-1"><span class="toctext">Collecting static functions in objects</span></li>
<li class="toclevel-1"><span class="toctext">Options</span></li>
<li class="toclevel-1"><span class="toctext">Customizing animations</span></li>
</ul>
<h3><a href="http://snook.ca/archives/javascript/jquery_plugin/" target="_blank">Developing A jQuery Plugin</a></h3>
<p><a href="http://snook.ca/archives/javascript/jquery_plugin/" target="_blank"><img alt="Develop jQuery Plugin" height="164" src="http://www.webresourcesdepot.com/wp-content/uploads/image/develop-jquery-plugin.jpg" width="480" /></a></p>
<p>Jonathan Snook is sharing his thoughts on <strong>developing a jQuery plugin</strong>.</p>
<p>A quick look to the basics &amp; advantages of &quot;why we need a plugin&quot;.</p>
<p><span id="more-848"></span></p>
<h3><a href="http://www.authenticsociety.com/blog/jQueryPluginTutorial_Beginner" target="_blank">jQuery Plugin Tutorial, In-Depth For Absolute Beginners</a></h3>
<p><a href="http://www.authenticsociety.com/blog/jQueryPluginTutorial_Beginner" target="_blank"><img alt="jQuery Create Plugin Tutorial" height="128" src="http://www.webresourcesdepot.com/wp-content/uploads/image/jquery-plugin-tut.gif" width="480" /></a></p>
<p>A tutorial for absolute beginners, including fresh JavaScript developers.</p>
<p>It clearly shows the advantages of jQuery &amp; creates a simple plugin named &quot;Shuffle&quot; by describing every step in detail.</p>
<h3><a href="http://webcloud.se/log/Building-jQuery-plugins/" target="_blank">Building jQuery Plugins</a></h3>
<p><a href="http://webcloud.se/article/Building_jQuery_plugins" target="_blank"><img alt="Building jQuery Plugins" height="164" src="http://www.webresourcesdepot.com/wp-content/uploads/image/jquery-plugin-dev.jpg" width="480" /></a></p>
<p>A tutorial for creating 2 different plugins:</p>
<ul>
<li><strong>jQuery.tabify</strong>: for creating tabbed contents easily</li>
<li><strong>jQuery.lessMore</strong>: a plugin that can hide any number of childs of a given parent object</li>
</ul>
<h3><a href="http://nettuts.com/tutorials/javascript-ajax/the-definitive-guide-to-creating-a-practical-jquery-plugin/" target="_blank">The Definitive Guide to Creating a Practical jQuery Plugin</a></h3>
<p><a href="http://nettuts.com/tutorials/javascript-ajax/the-definitive-guide-to-creating-a-practical-jquery-plugin/" target="_blank"><img alt="Create jQuery Plugin Guide" height="128" src="http://www.webresourcesdepot.com/wp-content/uploads/image/create-jquery-plugin.jpg" width="480" /></a></p>
<p>NETTUTS shows the <strong>steps of a jQuery plugin development</strong> by creating a simple image loader plugin.</p>
<p>The plugin loads the images at the backstage, they are saved in the visitor&rsquo;s browser cache, so, they will be usable throughout the rest of the site.</p>
<h3><a href="http://yensdesign.com/2008/12/how-to-create-a-plugin-for-jquery/" target="_blank">How To Create A Plugin For jQuery</a></h3>
<p><a href="http://yensdesign.com/2008/12/how-to-create-a-plugin-for-jquery/" target="_blank"><img alt="How To Build A jQuery Plugin" height="164" src="http://www.webresourcesdepot.com/wp-content/uploads/image/how-to-build-jquery-plugin.jpg" width="480" /></a></p>
<p>yensdesign describes the basics needed like the difference between <code>jQuery</code> &amp; <code>jQuery.fn</code> objects. Then creates an input highlighter plugin.</p>
<h3><a href="http://blog.jeremymartin.name/2008/02/building-your-first-jquery-plugin-that.html" target="_blank">Building Your First jQuery Plugin</a></h3>
<p><a href="http://blog.jeremymartin.name/2008/02/building-your-first-jquery-plugin-that.html" target="_blank"><img alt="jQuery Plugin Basics" height="128" src="http://www.webresourcesdepot.com/wp-content/uploads/image/jquery-plugin-basics.gif" width="480" /></a></p>
<p>This is the tutorial for creating the <a href="http://jmar777.blogspot.com/2008/02/jtruncate-text-truncation-for-jquery.html" target="_blank">jTruncate plugin</a>, a well-known plugin for truncating text.</p>
<p>It includes tips like using <code>jQuery</code> rather than <code>$</code>, usage of <code>extend</code> method &amp; more. At the end of the tutorial, you&#39;ll be created a fully-functional plugin.</p>
<h3><a href="http://nettuts.com/javascript-ajax/learn-how-to-create-a-jquery-plugin/" target="_blank">Learn How to Create a jQuery Plugin</a></h3>
<p><a href="http://nettuts.com/javascript-ajax/learn-how-to-create-a-jquery-plugin/" target="_blank"><img alt="How To Create A jQuery Plugin" height="128" src="http://www.webresourcesdepot.com/wp-content/uploads/image/how-to-create-jquery-plugin.jpg" width="480" /></a></p>
<p>A step-by-step <strong>tutorial on creating a jQuery plugin</strong> that dynamically adjusts the styling of a specified element for always keeping it vertically and horizontally centered on the page.</p>
<p>The tutorial is supported with a screencast as well.</p>
<h3><a href="http://www.learningjquery.com/2007/10/a-plugin-development-pattern" target="_blank">A Plugin Development Pattern</a></h3>
<p><a href="http://www.learningjquery.com/2007/10/a-plugin-development-pattern" target="_blank"><img alt="jQuery Plugin Development" height="128" src="http://www.webresourcesdepot.com/wp-content/uploads/image/jquery-plugin-development.gif" width="480" /></a></p>
<p>Karl Swedberg, a developer who already created several plugins, is sharing his experiences for a better <strong>jQuery plugin development</strong> process.</p>
<p><strong>Special Downloads:</strong><br />
<a href="http://www.webresourcesdepot.com/?download=jBasket" target="_blank">Ajaxed Add-To-Basket Scenarios With jQuery And PHP</a><br />
<a href="http://www.webresourcesdepot.com/?download=Free-Admin-Template" target="_blank">Free Admin Template For Web Applications</a><br />
<a href="http://www.webresourcesdepot.com/?download=jQuery-Dynamic-Drag-Drop" target="_blank">jQuery Dynamic Drag&#8217;n Drop</a><br />
<a href="http://www.webresourcesdepot.com/?download=sTwitter-1-0" target="_blank">ScheduledTweets</a></p>
<p><strong>Advertisements:</strong><br />
<a href="http://www.admintemplates.com" target="_blank">Professional XHTML Admin Template ($15 Discount With The Code: WRD.)</a><br />
<a href="http://www.xhtmchop.com" target="_blank">Psd to Xhtml</a><br />
<a href="http://www.sslmatic.com" target="_blank">SSLmatic &#8211; Cheap SSL Certificates (from $19.99/year)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webresourcesdepot.com/jquery-plugin-development-10-tutorials-to-get-started/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Sliding Top Menu With jQuery</title>
		<link>http://www.webresourcesdepot.com/sliding-top-menu-with-jquery/</link>
		<comments>http://www.webresourcesdepot.com/sliding-top-menu-with-jquery/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 05:01:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Extras]]></category>
		<category><![CDATA[Goodies]]></category>
		<category><![CDATA[License Free]]></category>
		<category><![CDATA[Menu & Navigation]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.webresourcesdepot.com/?p=341</guid>
		<description><![CDATA[<p><a href='http://rss.buysellads.com/click.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=341&c=7371' target='_blank'><img src='http://rss.buysellads.com/img.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=341&c=7371' border='0' alt='' /></a></p><p><a href='http://buysellads.com/buy/sitedetails/pubkey/ed230295611f656daf3115e6d682ca7d/zone/1259982' target='_blank'>Advertise here with BSA</a></p><br />Sliding menus are very effective in areas where we have limited space . This is a sliding top menu built with jQuery which can be fired through the open &#38; close buttons or with any tag with the related class name. You can also use it as an info box, login area &#38; more. Click [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://rss.buysellads.com/click.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=341&c=29317' target='_blank'><img src='http://rss.buysellads.com/img.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=341&c=29317' border='0' alt='' /></a></p><p><a href='http://buysellads.com/buy/sitedetails/pubkey/ed230295611f656daf3115e6d682ca7d/zone/1259982' target='_blank'>Advertise here with BSA</a></p><br /><p><strong>Sliding menus</strong> are very effective in areas where we have limited space .</p>
<p>This is a <strong>sliding top menu built with jQuery</strong> which can be fired through the open &amp; close buttons or with any tag with the related class name.</p>
<p>You can also use it as an info box, login area &amp; more.</p>
<p><a href="http://www.webresourcesdepot.com/wp-content/uploads/file/jquery-sliding-menu" target="_blank">Click here to see the final working demo of this <strong>jQuery sliding menu</strong></a>.</p>
<h3>It presents the menu when closed like this:</h3>
<p><img width="480" height="40" alt="Sliding Top Menu" src="http://www.webresourcesdepot.com/wp-content/uploads/sliding-top-menu.jpg" /></p>
<h3>And when opened:</h3>
<p><img width="480" height="150" alt="jQuery Sliding Menu" src="http://www.webresourcesdepot.com/wp-content/uploads/jquery-sliding-menu.jpg" /></p>
<p><a href="http://www.webresourcesdepot.com/wp-content/uploads/file/jquery-sliding-menu.zip"><img width="150" height="70" align="left" src="http://www.webresourcesdepot.com/wp-content/uploads/image/download.jpg" alt="Downloa jQuery Sliding Menu" style="margin-right: 5px;" /></a></p>
<p>&nbsp;</p>
<p><a href="http://www.webresourcesdepot.com/wp-content/uploads/file/jquery-sliding-menu" target="_blank">Click here to see the final working demo of this jQuery sliding menu</a>.</p>
<p>&nbsp;</p>
<h3>Step 1 &#8211; HTML:</h3>
<p><code>&lt;div id=&quot;sliderWrap&quot;&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;div id=&quot;openCloseIdentifier&quot;&gt;&lt;/div&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;div id=&quot;slider&quot;&gt;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;div id=&quot;sliderContent&quot;&gt;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Isn't this nice?<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/div&gt;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;div id=&quot;openCloseWrap&quot;&gt;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;a href=&quot;#&quot; class=&quot;topMenuAction&quot; id=&quot;topMenuImage&quot;&gt;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;img src=&quot;open.png&quot; alt=&quot;open&quot; /&gt;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/a&gt;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/div&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;/div&gt;<br />
&lt;/div&gt;</code><br />
&nbsp;</p>
<h3>Step 2 &#8211; CSS:</h3>
<p><code>&lt;style type=&quot;text/css&quot;&gt;<br />
body {<br />
margin: 0;<br />
font-size:16px;<br />
color: #000000;<br />
font-family:Arial, Helvetica, sans-serif;<br />
}<br />
#sliderWrap {<br />
margin: 0 auto;<br />
width: 300px;<br />
}<br />
#slider {<br />
position: absolute;<br />
background-image:url(slider.png);<br />
background-repeat:no-repeat;<br />
background-position: bottom;<br />
width: 300px;<br />
height: 159px;<br />
margin-top: -141px;<br />
}<br />
#slider img {<br />
border: 0;<br />
}<br />
#sliderContent {<br />
margin: 50px 0 0 50px;<br />
position: absolute;<br />
text-align:center;<br />
background-color:#FFFFCC;<br />
color:#333333;<br />
font-weight:bold;<br />
padding: 10px;<br />
}<br />
#header {<br />
margin: 0 auto;<br />
width: 600px;<br />
background-color: #F0F0F0;<br />
height: 200px;<br />
padding: 10px;<br />
}<br />
#openCloseWrap {<br />
position:absolute;<br />
margin: 143px 0 0 120px;<br />
font-size:12px;<br />
font-weight:bold;<br />
}<br />
&lt;/style&gt;</code><br />
&nbsp;</p>
<p>With the CSS file there are few major points:</p>
<ul>
<li>#slider has to be positioned absolutely, so it can overlay the other content.</li>
<li>#slider has a negative top-margin which hides it.</li>
<li>#sliderContent is positioned absolutely to not to crack the open/close buttons</li>
<li>#openCloseWrap holding the buttons are positioned absolutely too.</li>
</ul>
<h3>Step 3 &#8211; jQuery / JavaScript:</h3>
<p><code>&lt;script type=&quot;text/javascript&quot;&gt;<br />
$(document).ready(function() {<br />
&nbsp;&nbsp;&nbsp; $(&quot;.topMenuAction&quot;).click( function() {<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ($(&quot;#openCloseIdentifier&quot;).is(&quot;:hidden&quot;)) {<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $(&quot;#slider&quot;).animate({ <br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; marginTop: &quot;-141px&quot;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }, 500 );<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $(&quot;#topMenuImage&quot;).html('&lt;img src=&quot;open.png&quot;/&gt;');<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $(&quot;#openCloseIdentifier&quot;).show();<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } else {<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $(&quot;#slider&quot;).animate({ <br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; marginTop: &quot;0px&quot;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }, 500 );<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $(&quot;#topMenuImage&quot;).html('&lt;img src=&quot;close.png&quot;/&gt;');<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $(&quot;#openCloseIdentifier&quot;).hide();<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; });&nbsp; <br />
});<br />
&lt;/script&gt; </code></p>
<p>The main trick is changing the top margin of <code>#slider</code> and update the open / close images.</p>
<p>We have an empty element named <code>openCloseIdentifier</code> which shows us whether the menu is open or closed. We simply hide it when the menu is open and show when it is closed.</p>
<p><strong>Then all we do is:</strong></p>
<p>if <code>openCloseIdentifier = hidden</code> then close the menu or <code>if openCloseIdentifier = visible</code> then open the menu.</p>
<p><strong>Sliding effect</strong> can be fastened by changing the 500 value in <strong>JavaScript</strong> to a smaller number or else.</p>
<p>P.S. Down &amp; up arrow icons are from the <a target="_blank" href="http://www.everaldo.com/crystal/">Crystal Clear</a> icon set.</p>
<p><strong>Special Downloads:</strong><br />
<a href="http://www.webresourcesdepot.com/?download=jBasket" target="_blank">Ajaxed Add-To-Basket Scenarios With jQuery And PHP</a><br />
<a href="http://www.webresourcesdepot.com/?download=Free-Admin-Template" target="_blank">Free Admin Template For Web Applications</a><br />
<a href="http://www.webresourcesdepot.com/?download=jQuery-Dynamic-Drag-Drop" target="_blank">jQuery Dynamic Drag&#8217;n Drop</a><br />
<a href="http://www.webresourcesdepot.com/?download=sTwitter-1-0" target="_blank">ScheduledTweets</a></p>
<p><strong>Advertisements:</strong><br />
<a href="http://www.admintemplates.com" target="_blank">Professional XHTML Admin Template ($15 Discount With The Code: WRD.)</a><br />
<a href="http://www.xhtmchop.com" target="_blank">Psd to Xhtml</a><br />
<a href="http://www.sslmatic.com" target="_blank">SSLmatic &#8211; Cheap SSL Certificates (from $19.99/year)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webresourcesdepot.com/sliding-top-menu-with-jquery/feed/</wfw:commentRss>
		<slash:comments>150</slash:comments>
		</item>
		<item>
		<title>Load Content While Scrolling With jQuery</title>
		<link>http://www.webresourcesdepot.com/load-content-while-scrolling-with-jquery/</link>
		<comments>http://www.webresourcesdepot.com/load-content-while-scrolling-with-jquery/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 05:01:40 +0000</pubDate>
		<dc:creator>Umut M.</dc:creator>
				<category><![CDATA[Browsing]]></category>
		<category><![CDATA[CC License]]></category>
		<category><![CDATA[Extras]]></category>
		<category><![CDATA[Goodies]]></category>
		<category><![CDATA[License Free]]></category>
		<category><![CDATA[MIT License]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Scroll]]></category>

		<guid isPermaLink="false">http://www.webresourcesdepot.com/?p=327</guid>
		<description><![CDATA[<p><a href='http://rss.buysellads.com/click.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=327&c=14502' target='_blank'><img src='http://rss.buysellads.com/img.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=327&c=14502' border='0' alt='' /></a></p><p><a href='http://buysellads.com/buy/sitedetails/pubkey/ed230295611f656daf3115e6d682ca7d/zone/1259982' target='_blank'>Advertise here with BSA</a></p><br />We generally have lots of content to present but can not load all of it at once as it may take too long. I always loved the dZone&#8217;s Ajax content loading while scrolling feature and created a similar one using jQuery. I&#8217;m pleased to share with WebResourcesDepot readers (Check the demo &#8211; scroll down to [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://rss.buysellads.com/click.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=327&c=19205' target='_blank'><img src='http://rss.buysellads.com/img.php?z=1259982&k=ed230295611f656daf3115e6d682ca7d&a=327&c=19205' border='0' alt='' /></a></p><p><a href='http://buysellads.com/buy/sitedetails/pubkey/ed230295611f656daf3115e6d682ca7d/zone/1259982' target='_blank'>Advertise here with BSA</a></p><br /><p>We generally have lots of content to present but can not load all of it at once as it may take too long.</p>
<p>I always loved the <strong>dZone&#8217;s Ajax content loading while scrolling</strong> feature and created a similar one using <strong>jQuery.</strong></p>
<p>I&#8217;m pleased to share with <strong>WebResourcesDepot</strong> readers (<a href="http://www.webresourcesdepot.com/dnspinger/" target="_blank"><strong>Check the demo</strong></a> &#8211; scroll down to see new content in the demo)</p>
<p>This <strong>Ajax auto content loading</strong> can very be handy in almost every project. <span style="font-weight: bold;">D</span><strong>on&#8217;t forget to bookmark it (<a target="_blank" href="http://del.icio.us/webresourcesdepot?url=http://www.webresourcesdepot.com/load-content-while-scrolling-with-jquery-tutorial%2F&amp;title=Load Content While Scrolling With jQuery">del.icio.us link</a>)</strong>.</p>
<p><a target="_blank" href="http://www.webresourcesdepot.com/dnspinger"><img width="480" height="84" alt="jQuery Load Content While Scrolling" src="http://www.webresourcesdepot.com/wp-content/uploads/jquery-content-scroller.gif" /></a></p>
<p><a href="http://www.webresourcesdepot.com/wp-content/uploads/file/wrd-scroll.zip" target="_blank"><img width="150" height="70" align="left" style="margin-right: 10px;" src="http://www.webresourcesdepot.com/wp-content/uploads/image/download.jpg" alt="Download Load Content While Scrolling With jQuery" /></a></p>
<p>
Download package includes a working demo coded with ASP with a test MySQL database. ASP code is just a simple query so you can switch it with a one you like easily.</p>
<p>&nbsp;</p>
<p><span id="more-327"></span></p>
<h3>What is loading content while scrolling?</h3>
<p>When we are <strong>scrolling</strong> down a webpage, the code recognizes that you are at the bottom and <strong>auto-loads new content</strong>.</p>
<h3>Why to use it?</h3>
<p>It helps increasing the initial load speeds of pages faster and users will have to load only the content they see.</p>
<h3>How it works? (<a target="_blank" href="http://www.webresourcesdepot.com/dnspinger/">Check the demo</a>)</h3>
<p>In our case, we have DIVS holding contents where every DIV ID is content&#8217;s database ID.</p>
<ul>
<li>Content structure is like:</li>
</ul>
<p><code>&lt;div class=&quot;wrdLatest&quot; id=9&gt;content&lt;/div&gt;<br />
&lt;div </code><code>class</code><code>=&quot;wrdLatest&quot; id=8&gt;content&lt;/div&gt;</code></p>
<ul>
<li>We create a function sending a query to a dynamic file with the DIV ID of the latest wrdLatest DIV (and also put a loader image):</li>
</ul>
<p style="text-align: left;"><code>function lastPostFunc() <br />
{ <br />
&nbsp;&nbsp;&nbsp; $('div#lastPostsLoader').html('&lt;img src=&quot;bigLoader.gif&quot;&gt;');<br />
&nbsp;&nbsp;&nbsp; $.post(&quot;scroll.asp?action=getLastPosts&amp;lastID=&quot; + $(&quot;.wrdLatest:last&quot;).attr(&quot;id&quot;), </code> <code> &nbsp;&nbsp;&nbsp; <br />
</code></p>
<p style="text-align: left;"><code>&nbsp;&nbsp;&nbsp; function(data){<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (data != &quot;&quot;) {<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $(&quot;.wrdLatest:last&quot;).after(data);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $('div#lastPostsLoader').empty();<br />
&nbsp;&nbsp;&nbsp; });<br />
};&nbsp;<br />
</code></p>
<ul>
<li>When a user <strong>scrolls down</strong>, we understand that the scroller is at the bottom with teh function below and fire the <code>lastPostFunc</code> function.</li>
</ul>
<p><code>$(window).scroll(function(){<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if&nbsp; ($(window).scrollTop() == $(document).height() - $(window).height()){<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; lastPostFunc();<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
}); </code></p>
<p>I have <a target="_blank" href="http://www.webresourcesdepot.com/dnspinger/">applied the demo to the DNSPinger service</a>. Simply scroll down to see new content loading.</p>
<h3>Dependencies</h3>
<p><strike>This is a very simple code that uses <strong>jQuery&#8217;s</strong> great </strike><a target="_blank" href="http://brandonaaron.net/docs/dimensions/"><strike><strong>dimensions plugin</strong></strike></a><strike> that helps us understand that we are at the bottom of the page.</strike> <strong>Update: Dimensions plugin</strong> is included with <strong>jQuery</strong> 1.2.6 and no need to include it as an extra.</p>
<p>Besides that, you can improve the code to detect the users sceen-size and load your initial content according to that screen size.</p>
<p><strong>Special Downloads:</strong><br />
<a href="http://www.webresourcesdepot.com/?download=jBasket" target="_blank">Ajaxed Add-To-Basket Scenarios With jQuery And PHP</a><br />
<a href="http://www.webresourcesdepot.com/?download=Free-Admin-Template" target="_blank">Free Admin Template For Web Applications</a><br />
<a href="http://www.webresourcesdepot.com/?download=jQuery-Dynamic-Drag-Drop" target="_blank">jQuery Dynamic Drag&#8217;n Drop</a><br />
<a href="http://www.webresourcesdepot.com/?download=sTwitter-1-0" target="_blank">ScheduledTweets</a></p>
<p><strong>Advertisements:</strong><br />
<a href="http://www.admintemplates.com" target="_blank">Professional XHTML Admin Template ($15 Discount With The Code: WRD.)</a><br />
<a href="http://www.xhtmchop.com" target="_blank">Psd to Xhtml</a><br />
<a href="http://www.sslmatic.com" target="_blank">SSLmatic &#8211; Cheap SSL Certificates (from $19.99/year)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webresourcesdepot.com/load-content-while-scrolling-with-jquery/feed/</wfw:commentRss>
		<slash:comments>140</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using wincache
Page Caching using wincache (User agent is rejected)
Database Caching using wincache

Served from: www.webresourcesdepot.com @ 2012-02-12 17:37:49 -->
