<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>InTechgrity</title>
	
	<link>http://www.intechgrity.com</link>
	<description>Amalgamating Life &amp; Technology</description>
	<lastBuildDate>Fri, 18 May 2012 04:22:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/greentechspot" /><feedburner:info uri="greentechspot" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.0/</creativeCommons:license><image><link>http://creativecommons.org/licenses/by-nc-nd/2.0/</link><url>http://creativecommons.org/images/public/somerights20.gif</url><title>Some Rights Reserved</title></image><feedburner:emailServiceId>greentechspot</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>WordPress Multisite compatibility for timthumb</title>
		<link>http://feedproxy.google.com/~r/greentechspot/~3/noGLbLbo1Rc/</link>
		<comments>http://www.intechgrity.com/wordpress-multisite-compatibility-for-timthumb/#comments</comments>
		<pubDate>Thu, 17 May 2012 12:30:14 +0000</pubDate>
		<dc:creator>Swashata</dc:creator>
				<category><![CDATA[WP Programming]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress hacks]]></category>

		<guid isPermaLink="false">http://www.intechgrity.com/?p=1085</guid>
		<description><![CDATA[<p><p>Original post published <a href="<a href="http://www.intechgrity.com/wordpress-multisite-compatibility-for-timthumb/">WordPress Multisite compatibility for timthumb</a>">here</a></p><p>Ever found the necessity to use TimThumb for your WordPress theme and/or plugin? Then you should&#8217;ve faced the problem where you can not tell TimThumb about the correct location of image files in WordPress Multi-Site setup and in return TimThumb gave you internal image not found error. The tutorial over binarymoon is a bit backdated [...]</p></p><p>- By <a href="http://www.intechgrity.com">InTechgrity - Amalgamating Life &amp; Technology</a></p>
Related posts:<ol>
<li><a href='http://www.intechgrity.com/timthumb-vulerability-how-it-got-hacked-how-to-recover/' rel='bookmark' title='TimThumb vulerability &#8211; How it got hacked &amp; how to recover'>TimThumb vulerability &#8211; How it got hacked &#038; how to recover</a></li>
<li><a href='http://www.intechgrity.com/how-to-get-the-souce-url-of-the-featured-image-in-wordpress/' rel='bookmark' title='How to get the souce URL of the featured image in WordPress'>How to get the souce URL of the featured image in WordPress</a></li>
<li><a href='http://www.intechgrity.com/add-dynamic-login-logout-n-site-admin-button-to-wordpress-using-wp-api/' rel='bookmark' title='Add dynamic Login Logout n Site Admin button to WordPress using WP API'>Add dynamic Login Logout n Site Admin button to WordPress using WP API</a></li>
<li><a href='http://www.intechgrity.com/make-google-adsense-custom-search-with-wordpress-custom-page-template/' rel='bookmark' title='Make Google Adsense custom Search with WordPress Custom Page Template'>Make Google Adsense custom Search with WordPress Custom Page Template</a></li>
<li><a href='http://www.intechgrity.com/add-archive-page-wordpress-blog-custom-page-template/' rel='bookmark' title='Howto: Add an Archive Page to your WordPress blog using Custom Page Template'>Howto: Add an Archive Page to your WordPress blog using Custom Page Template</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/L1BSiVUl62pHKLn_RSDERy6W294/0/da"><img src="http://feedads.g.doubleclick.net/~a/L1BSiVUl62pHKLn_RSDERy6W294/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/L1BSiVUl62pHKLn_RSDERy6W294/1/da"><img src="http://feedads.g.doubleclick.net/~a/L1BSiVUl62pHKLn_RSDERy6W294/1/di" border="0" ismap="true"></img></a></p><p>Original post published <a href="<a href="http://www.intechgrity.com/wordpress-multisite-compatibility-for-timthumb/">WordPress Multisite compatibility for timthumb</a>">here</a></p><p><a href="http://www.intechgrity.com/wp-content/uploads/2012/05/wordpress-ms-timthumb.png"><img class="alignright size-full wp-image-1128" title="wordpress-ms-timthumb" src="http://www.intechgrity.com/wp-content/uploads/2012/05/wordpress-ms-timthumb.png" alt="" width="300" height="300" /></a>Ever found the necessity to use <a href="http://www.binarymoon.co.uk/projects/timthumb/" target="_blank">TimThumb</a> for your WordPress theme and/or plugin? Then you should&#8217;ve faced the problem where you can not tell TimThumb about the correct location of image files in WordPress Multi-Site setup and in return TimThumb gave you internal image not found error. The tutorial over <a href="http://www.binarymoon.co.uk/2009/10/timthumb-wordpress-mu/" target="_blank">binarymoon</a> is a bit backdated as it uses custom fields to get and set the image with TimThumb. The obvious question which arises is, how to use the <a title="Getting Post thumbnail on WordPress 3 w/ w/o specific Post ID" href="http://www.intechgrity.com/getting-post-thumbnail-on-wordpress-3-w-wo-specific-post-id/">WordPress&#8217; own</a> <a title="Setting Post Thumbnail on WordPress with custom size and Cropping – A simpler approach" href="http://www.intechgrity.com/setting-post-thumbnail-on-wordpress-with-custom-size-and-cropping-a-simpler-approach/">featured image</a> with TimThumb to give it maximum resizing capability. Previously, we have discussed about how to <a title="How to get the souce URL of the featured image in WordPress" href="http://www.intechgrity.com/how-to-get-the-souce-url-of-the-featured-image-in-wordpress/">get the image src from the featured image HTML</a> and use it for other purposes like CSS etc. Now, we shall see, how to use the original image source and modify it so that it works with TimThumb (for WP MS ofcourse).</p>
<h2>#1: Understanding the concept:</h2>
<p>What WordPress does is, it gives some nicer URL to the static files in case of MultiSite setup. In general setup (without networking), the file URL is like this</p>
<pre class="brush: plain; title: ; notranslate">

http://yoursite.com/wp-content/uploads/2012/05/image.jpg
</pre>
<p>Which is just the absolute URL of the file.</p>
<p>But, for WordPress it becomes like this</p>
<pre class="brush: plain; title: ; notranslate">

http://sub.yoursite.com/files/2012/05/image.jpg
</pre>
<p>Which is obviously not the absolute static URL of the file. WordPress internally modifies the path via some htaccess rewrite to push the original content at this URL.</p>
<p>The main reason why TimThumb doesn&#8217;t work is, because, there is no <span class="spanlight">real</span> directory files anywhere on the root of your site. So, we have to either rewrite the URL before passing it to TimThumb or we have to somehow tell TimThumb about this issue. The second solution is not feasible as it involves editing the core of the script, which means, you have to do it again after any update. So, we shall use the first technique within our themes or plugins to make it WP MS compatible. Also, we shall explicitly check the image URL for the presence of <span class="spanlight">/files/</span> (uploaded media) and <span class="spanlight">/wp-content/</span> (theme or plugin files) and will treat them properly.</p>
<h2>#2: The code behind the compatibility:</h2>
<pre class="brush: php; title: ; notranslate">
/**
 * TimThumb Image
 *
 * **Properly** appends the source image URL to timthumb for WP MS compatibility
 * Explicitly check the presence of /files/ and /wp-content/ in the URI and treats accordingly.
 * Has compatibility for both uploaded media as well as theme/plugin media files.
 *
 * You can also set height and width using the parameters
 *
 * @author Swashata
 * @param String $src The URL of the original image 'http://path/to/image.jpg
 * @param Int $h The height of the image
 * @param Int $w The width of the image
 * @return String The modified timthumb URL of the image
 */
function itg_timthumb_image($src, $h = 50, $w = 50) {
    //set your timthumb url
    $timthumb_url = get_bloginfo('wpurl') . '/path/to/timthumb.php';
    //check for multisite
    if(is_multisite()) {
        //get rid of the www part from the HTTP_HOST
        $host = preg_replace('/^www\./i', '', $_SERVER['HTTP_HOST']);
        if(preg_match('/https?:\/\/(?:www\.)?' . $host . '/i', $src)) { //check if internal
            //is it a request for directory wp-content?
            if(preg_match('/\/wp-content\//', $src)) {
                $src_parts = explode('/wp-content/', $src);
                $src = '/wp-content/' . $src_parts[1];
            }
            //is it a request for /files/ virtual directory
            else if(preg_match('/\/files\//', $src)) {
                $src_parts = explode('/files/', $src);
                $src = '/blogs.dir/' . get_current_blog_id() . '/files/' . $src_parts[1];
            }
        }
    }
    return $timthumb_url . '?src=' . urlencode($src) . '&amp;amp;h=' . $h . '&amp;amp;w=' . $w . '&amp;amp;zc=1';
}
</pre>
<p>And finally you call the function to do what you want. Note that you do need to pass the raw image URL as the <span class="code">$src</span> variable. If you wish to TimThumb your featured images, then use the function used <a title="How to get the souce URL of the featured image in WordPress" href="http://www.intechgrity.com/how-to-get-the-souce-url-of-the-featured-image-in-wordpress/">here</a> and call the above function like this:</p>
<pre class="brush: php; title: ; notranslate">
//get 200 X 200 thumbnail for the current post featured image
itg_timthumb_image(itg_get_the_post_thumbnail_url(), 200, 200);
</pre>
<p>So that was the most complete and simple solution I could think of while making my WordPress things compatible with MultiSite and TimThumb. If you know any better technique or have any problem using this, then do let us know.</p>
<p>Related posts:<ol>
<li><a href='http://www.intechgrity.com/timthumb-vulerability-how-it-got-hacked-how-to-recover/' rel='bookmark' title='TimThumb vulerability &#8211; How it got hacked &amp; how to recover'>TimThumb vulerability &#8211; How it got hacked &#038; how to recover</a></li>
<li><a href='http://www.intechgrity.com/how-to-get-the-souce-url-of-the-featured-image-in-wordpress/' rel='bookmark' title='How to get the souce URL of the featured image in WordPress'>How to get the souce URL of the featured image in WordPress</a></li>
<li><a href='http://www.intechgrity.com/add-dynamic-login-logout-n-site-admin-button-to-wordpress-using-wp-api/' rel='bookmark' title='Add dynamic Login Logout n Site Admin button to WordPress using WP API'>Add dynamic Login Logout n Site Admin button to WordPress using WP API</a></li>
<li><a href='http://www.intechgrity.com/make-google-adsense-custom-search-with-wordpress-custom-page-template/' rel='bookmark' title='Make Google Adsense custom Search with WordPress Custom Page Template'>Make Google Adsense custom Search with WordPress Custom Page Template</a></li>
<li><a href='http://www.intechgrity.com/add-archive-page-wordpress-blog-custom-page-template/' rel='bookmark' title='Howto: Add an Archive Page to your WordPress blog using Custom Page Template'>Howto: Add an Archive Page to your WordPress blog using Custom Page Template</a></li>
</ol></p><p>- By <a href="http://www.intechgrity.com">InTechgrity - Amalgamating Life &amp; Technology</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/greentechspot?a=noGLbLbo1Rc:_VLjMr78GRI:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=noGLbLbo1Rc:_VLjMr78GRI:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=noGLbLbo1Rc:_VLjMr78GRI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=noGLbLbo1Rc:_VLjMr78GRI:nQ_hWtDbxek"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=nQ_hWtDbxek" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=noGLbLbo1Rc:_VLjMr78GRI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=noGLbLbo1Rc:_VLjMr78GRI:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=noGLbLbo1Rc:_VLjMr78GRI:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=noGLbLbo1Rc:_VLjMr78GRI:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=noGLbLbo1Rc:_VLjMr78GRI:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=noGLbLbo1Rc:_VLjMr78GRI:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=noGLbLbo1Rc:_VLjMr78GRI:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=noGLbLbo1Rc:_VLjMr78GRI:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=noGLbLbo1Rc:_VLjMr78GRI:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=noGLbLbo1Rc:_VLjMr78GRI:YwkR-u9nhCs"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=YwkR-u9nhCs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=noGLbLbo1Rc:_VLjMr78GRI:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=noGLbLbo1Rc:_VLjMr78GRI:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=noGLbLbo1Rc:_VLjMr78GRI:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=noGLbLbo1Rc:_VLjMr78GRI:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=noGLbLbo1Rc:_VLjMr78GRI:-BTjWOF_DHI" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/greentechspot/~4/noGLbLbo1Rc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.intechgrity.com/wordpress-multisite-compatibility-for-timthumb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.intechgrity.com/wordpress-multisite-compatibility-for-timthumb/</feedburner:origLink></item>
		<item>
		<title>How to get the souce URL of the featured image in WordPress</title>
		<link>http://feedproxy.google.com/~r/greentechspot/~3/NRBOPDwT6As/</link>
		<comments>http://www.intechgrity.com/how-to-get-the-souce-url-of-the-featured-image-in-wordpress/#comments</comments>
		<pubDate>Wed, 16 May 2012 13:01:37 +0000</pubDate>
		<dc:creator>Swashata</dc:creator>
				<category><![CDATA[WP Programming]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress api]]></category>
		<category><![CDATA[wordpress hacks]]></category>

		<guid isPermaLink="false">http://www.intechgrity.com/?p=1117</guid>
		<description><![CDATA[<p><p>Original post published <a href="<a href="http://www.intechgrity.com/how-to-get-the-souce-url-of-the-featured-image-in-wordpress/">How to get the souce URL of the featured image in WordPress</a>">here</a></p><p>Previously we have talked about setting and getting featured images in WordPress using built in APIs. But, one of the drawback of this method is, it returns or prints the image with proper HTML. In other words, it does not give you the URL of the image. It becomes necessary if you want to Pass [...]</p></p><p>- By <a href="http://www.intechgrity.com">InTechgrity - Amalgamating Life &amp; Technology</a></p>
Related posts:<ol>
<li><a href='http://www.intechgrity.com/add-dynamic-login-logout-n-site-admin-button-to-wordpress-using-wp-api/' rel='bookmark' title='Add dynamic Login Logout n Site Admin button to WordPress using WP API'>Add dynamic Login Logout n Site Admin button to WordPress using WP API</a></li>
<li><a href='http://www.intechgrity.com/get-post-count-of-a-category-including-sub-categories-in-wordpress/' rel='bookmark' title='Get post count of a category including sub-categories in WordPress'>Get post count of a category including sub-categories in WordPress</a></li>
<li><a href='http://www.intechgrity.com/properly-add-pagination-to-your-wordpress-plugin/' rel='bookmark' title='Properly add pagination to your WordPress Plugin'>Properly add pagination to your WordPress Plugin</a></li>
<li><a href='http://www.intechgrity.com/add-archive-page-wordpress-blog-custom-page-template/' rel='bookmark' title='Howto: Add an Archive Page to your WordPress blog using Custom Page Template'>Howto: Add an Archive Page to your WordPress blog using Custom Page Template</a></li>
<li><a href='http://www.intechgrity.com/make-google-adsense-custom-search-with-wordpress-custom-page-template/' rel='bookmark' title='Make Google Adsense custom Search with WordPress Custom Page Template'>Make Google Adsense custom Search with WordPress Custom Page Template</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/3sRRug6Ykx_Wj0Mg6_gx2cbbOMs/0/da"><img src="http://feedads.g.doubleclick.net/~a/3sRRug6Ykx_Wj0Mg6_gx2cbbOMs/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/3sRRug6Ykx_Wj0Mg6_gx2cbbOMs/1/da"><img src="http://feedads.g.doubleclick.net/~a/3sRRug6Ykx_Wj0Mg6_gx2cbbOMs/1/di" border="0" ismap="true"></img></a></p><p>Original post published <a href="<a href="http://www.intechgrity.com/how-to-get-the-souce-url-of-the-featured-image-in-wordpress/">How to get the souce URL of the featured image in WordPress</a>">here</a></p><p><a href="http://www.intechgrity.com/wp-content/uploads/2012/05/image-url-featured-post-wp.png"><img class="alignright size-thumbnail wp-image-1124" title="image-url-featured-post-wp" src="http://www.intechgrity.com/wp-content/uploads/2012/05/image-url-featured-post-wp-150x150.png" alt="" width="150" height="150" /></a>Previously we have talked about <a title="Setting Post Thumbnail on WordPress with custom size and Cropping – A simpler approach" href="http://www.intechgrity.com/setting-post-thumbnail-on-wordpress-with-custom-size-and-cropping-a-simpler-approach/">setting</a> and <a title="Getting Post thumbnail on WordPress 3 w/ w/o specific Post ID" href="http://www.intechgrity.com/getting-post-thumbnail-on-wordpress-3-w-wo-specific-post-id/">getting</a> featured images in WordPress using built in APIs. But, one of the drawback of this method is, it returns or prints the image with proper HTML. In other words, it does not give you the URL of the image. It becomes necessary if you want to</p>
<ul>
<li>Pass the URL to scripts like say TimThumb for dynamic resizing.</li>
<li>Use the URL for inline css styling</li>
<li>and others&#8230;</li>
</ul>
<p>So, in this tutorial we will learn how to do that by passing the fetched image HTML to our custom function.</p>
<h2>#1: Understanding the concept:</h2>
<h3>#1.1: The output HTML of the API:</h3>
<p>When we use <span class="code">get_the_post_thumbnail</span>, then it returns a nice HTML code which looks like this&#8230;</p>
<pre class="brush: xml; title: ; notranslate">
    &lt;img width=&quot;50&quot; height=&quot;50&quot; title=&quot;3d_pie_chart_icon_psd_by_psdblast-d4jqqn4&quot; alt=&quot;3d_pie_chart_icon_psd_by_psdblast-d4jqqn4&quot; src=&quot;http://localhost/wp/wp-content/uploads/2012/05/img.jpg&quot; /&gt;
</pre>
<h3>#1.2: What we need to do:</h3>
<p>So, somehow we need to extract the src attribute from the HTML img tag. Now, there are a number of ways for doing this. I will discuss the fastest and simplest <span class="code">preg_match</span> method, where you have to pass the output string and will get the src attribute.</p>
<h2>#2: Using preg_match to get the source URL</h2>
<p>From the output HTML we see that</p>
<ol>
<li>The image tag starts with <em>&lt;img</em>.</li>
<li>There can be almost anything or nothing before the <em>src</em> keyword.</li>
<li>Inside the src the URL of the image is written in between two double quote. <em>It can contain anything except double quotes</em>.</li>
<li>After src there can be again anything or nothing.</li>
</ol>
<p>So, keeping in these strategies in mind, we make our regular expression to work with preg_match.</p>
<pre class="brush: php; title: ; notranslate">
$src_pattern = '/&lt;img.+src=[\'&quot;]([^\'&quot;]+)[\'&quot;].*&gt;/i';
</pre>
<p>Now we use the preg_match like this:</p>
<pre class="brush: php; title: ; notranslate">
$src = '';
$matches = array();
if(preg_match($src_pattern, $text, $matches)) {
    $src = $matches[1];
}
</pre>
<p>Where the <span class="code">$text</span> variable should hold the HTML returned by the get_the_post_thumbnail function. So, we put together all the code and come up with something like this</p>
<pre class="brush: php; title: ; notranslate">
/**
 * Get the post thumbnail URL
 *
 * Automatically gets and returns the source URL of the full-sized featured image
 * of the current post in the loop.
 *
 * You can also change the parameters below for more flexibility
 *
 * @param int $id The id of the post. If null, then it will fetch the current post thumbnail.
 * @param String $size The registered image size name. Default is full, which gives the full-size image url. You set it to post-thumbnail or anything else.
 * @return String The URL of the featured image of the queried size.
 */
function itg_get_the_post_thumbnail_url($id = null, $size = 'full') {
    //if no post thumbnail is set, return empty string
    if(!has_post_thumbnail($id))
        return '';

    //get the post thumbnail
    $text = get_the_post_thumbnail($id, $size);

    //initialize the variables
    $src = '';
    $matches = array();

    //set the match string
    $src_pattern = '/&lt;img.+src=[\'&quot;]([^\'&quot;]+)[\'&quot;].*&gt;/i';

    //match it
    if(preg_match($src_pattern, $text, $matches)) {
        $src = $matches[1];
    }

    return trim($src);
}
</pre>
<p>What the function does is it automatically gets the featured image of the current post in the loop and returns its full sized image URL. But it has some flexibility as well. As the comments say, the available parameters are:</p>
<ul>
<li><strong>$id</strong> &#8211; <em>Integer</em> &#8211; The id of the post. If null, then it will fetch the current post thumbnail.</li>
<li><strong>$size</strong> &#8211; <em>String </em>- The registered image size name. Default is full, which gives the full-size image url. You set it to post-thumbnail or anything else.</li>
<li><strong>return </strong>- <em>String</em> &#8211; The URL of the featured image of the queried size.</li>
</ul>
<p>So when ever you need to get the image url, you call it like this:</p>
<pre class="brush: php; title: ; notranslate">
//get full sized, current post
$img_src = itg_get_the_post_thumbnail_url();

//get thumbnail sized, custom post
//replace with your post ID
$img_src = itg_get_the_post_thumbnail_url(10, 'post-thumbnail');

//get thumbnail sized, current post
$img_src = itg_get_the_post_thumbnail_url(null, 'post-thumbnail');

//get full sized, custom post
$img_src = itg_get_the_post_thumbnail_url(10);
</pre>
<p>You are free to use this code anywhere you like. It should do what you want. If there is anything else you want to know, then just comment.</p>
<p>Related posts:<ol>
<li><a href='http://www.intechgrity.com/add-dynamic-login-logout-n-site-admin-button-to-wordpress-using-wp-api/' rel='bookmark' title='Add dynamic Login Logout n Site Admin button to WordPress using WP API'>Add dynamic Login Logout n Site Admin button to WordPress using WP API</a></li>
<li><a href='http://www.intechgrity.com/get-post-count-of-a-category-including-sub-categories-in-wordpress/' rel='bookmark' title='Get post count of a category including sub-categories in WordPress'>Get post count of a category including sub-categories in WordPress</a></li>
<li><a href='http://www.intechgrity.com/properly-add-pagination-to-your-wordpress-plugin/' rel='bookmark' title='Properly add pagination to your WordPress Plugin'>Properly add pagination to your WordPress Plugin</a></li>
<li><a href='http://www.intechgrity.com/add-archive-page-wordpress-blog-custom-page-template/' rel='bookmark' title='Howto: Add an Archive Page to your WordPress blog using Custom Page Template'>Howto: Add an Archive Page to your WordPress blog using Custom Page Template</a></li>
<li><a href='http://www.intechgrity.com/make-google-adsense-custom-search-with-wordpress-custom-page-template/' rel='bookmark' title='Make Google Adsense custom Search with WordPress Custom Page Template'>Make Google Adsense custom Search with WordPress Custom Page Template</a></li>
</ol></p><p>- By <a href="http://www.intechgrity.com">InTechgrity - Amalgamating Life &amp; Technology</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/greentechspot?a=NRBOPDwT6As:Kk-kNCrslm8:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=NRBOPDwT6As:Kk-kNCrslm8:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=NRBOPDwT6As:Kk-kNCrslm8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=NRBOPDwT6As:Kk-kNCrslm8:nQ_hWtDbxek"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=nQ_hWtDbxek" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=NRBOPDwT6As:Kk-kNCrslm8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=NRBOPDwT6As:Kk-kNCrslm8:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=NRBOPDwT6As:Kk-kNCrslm8:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=NRBOPDwT6As:Kk-kNCrslm8:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=NRBOPDwT6As:Kk-kNCrslm8:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=NRBOPDwT6As:Kk-kNCrslm8:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=NRBOPDwT6As:Kk-kNCrslm8:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=NRBOPDwT6As:Kk-kNCrslm8:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=NRBOPDwT6As:Kk-kNCrslm8:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=NRBOPDwT6As:Kk-kNCrslm8:YwkR-u9nhCs"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=YwkR-u9nhCs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=NRBOPDwT6As:Kk-kNCrslm8:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=NRBOPDwT6As:Kk-kNCrslm8:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=NRBOPDwT6As:Kk-kNCrslm8:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=NRBOPDwT6As:Kk-kNCrslm8:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=NRBOPDwT6As:Kk-kNCrslm8:-BTjWOF_DHI" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/greentechspot/~4/NRBOPDwT6As" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.intechgrity.com/how-to-get-the-souce-url-of-the-featured-image-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.intechgrity.com/how-to-get-the-souce-url-of-the-featured-image-in-wordpress/</feedburner:origLink></item>
		<item>
		<title>10 free minimalist grey scale icon sets for your web design</title>
		<link>http://feedproxy.google.com/~r/greentechspot/~3/0cdSI8PUwIE/</link>
		<comments>http://www.intechgrity.com/10-free-minimalist-grey-scale-icon-sets-for-your-web-design/#comments</comments>
		<pubDate>Tue, 15 May 2012 17:44:00 +0000</pubDate>
		<dc:creator>Swashata</dc:creator>
				<category><![CDATA[Web Designing]]></category>
		<category><![CDATA[Icons]]></category>

		<guid isPermaLink="false">http://www.intechgrity.com/?p=1094</guid>
		<description><![CDATA[<p><p>Original post published <a href="<a href="http://www.intechgrity.com/10-free-minimalist-grey-scale-icon-sets-for-your-web-design/">10 free minimalist grey scale icon sets for your web design</a>">here</a></p><p>Previously, we had discussed about websites providing FREE icons and background patterns. Today we are going to give you some modern minimalist icon sets made on grey scale. The awesome thing about grey scale icons are, they blend with almost any design. So, we searched over the Internet and finally ended up with 10 most [...]</p></p><p>- By <a href="http://www.intechgrity.com">InTechgrity - Amalgamating Life &amp; Technology</a></p>
Related posts:<ol>
<li><a href='http://www.intechgrity.com/15-free-web-icons-background/' rel='bookmark' title='15+ Free Web-Icons &amp; Background Patterns/Texture download sites to boost your Blog &amp; Website designing'>15+ Free Web-Icons &amp; Background Patterns/Texture download sites to boost your Blog &amp; Website designing</a></li>
<li><a href='http://www.intechgrity.com/huge-collection-of-css-js-jquery/' rel='bookmark' title='Huge collection of CSS, JS &amp; jQuery Dropdown Navigation menus for FREE &#124; Use on your Web site or Blog'>Huge collection of CSS, JS &amp; jQuery Dropdown Navigation menus for FREE &#124; Use on your Web site or Blog</a></li>
<li><a href='http://www.intechgrity.com/create-ajax-style-loading-animated-gif/' rel='bookmark' title='Create Ajax style Loading Animated Gif images easily with 3 Free Online Generators'>Create Ajax style Loading Animated Gif images easily with 3 Free Online Generators</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/n0AKR8U23_xhVScLlZBZLVLq9SI/0/da"><img src="http://feedads.g.doubleclick.net/~a/n0AKR8U23_xhVScLlZBZLVLq9SI/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/n0AKR8U23_xhVScLlZBZLVLq9SI/1/da"><img src="http://feedads.g.doubleclick.net/~a/n0AKR8U23_xhVScLlZBZLVLq9SI/1/di" border="0" ismap="true"></img></a></p><p>Original post published <a href="<a href="http://www.intechgrity.com/10-free-minimalist-grey-scale-icon-sets-for-your-web-design/">10 free minimalist grey scale icon sets for your web design</a>">here</a></p><p><a href="http://www.intechgrity.com/wp-content/uploads/2012/05/10-minimalist-grey-scale-icon-set.png"><img class="alignright size-thumbnail wp-image-1098" title="10-minimalist-grey-scale-icon-set" src="http://www.intechgrity.com/wp-content/uploads/2012/05/10-minimalist-grey-scale-icon-set-150x150.png" alt="" width="150" height="150" /></a>Previously, we had discussed <a title="15+ Free Web-Icons &amp; Background Patterns/Texture download sites to boost your Blog &amp; Website designing" href="http://www.intechgrity.com/15-free-web-icons-background/">about websites providing FREE icons and background patterns</a>. Today we are going to give you some modern minimalist icon sets made on grey scale. The awesome thing about grey scale icons are, they blend with almost any design. So, we searched over the Internet and finally ended up with 10 most beautiful icon packs. Most of them are free for both commercial as well as personal, and only requires an attribution. But do check the licenses yourself before using it on any commercial projects. So, here we go with the list:</p>
<h2>Big Sized Icons with Included PSD</h2>
<h3>#1: Retina Display Icon Set</h3>
<p style="text-align: center;"><a href="http://blog.twg.ca/2010/11/retina-display-icon-set/" target="_blank"><img class="aligncenter size-full wp-image-1106" title="retina-display-icon-set" src="http://www.intechgrity.com/wp-content/uploads/2012/05/retina-display-icon-set.png" alt="" width="560" height="150" /></a><strong>Sizes:</strong> 64&#215;64, 48&#215;48, 24&#215;24 (<em>PSD included</em>) <strong>Total Icons: </strong>147 <strong>Download: </strong><a href="http://blog.twg.ca/2010/11/retina-display-icon-set/" target="_blank">Click here</a></p>
<h3>#2: WPZOOM Developer Icon Set</h3>
<p style="text-align: center;"><a href="http://www.wpzoom.com/wpzoom/new-freebie-wpzoom-developer-icon-set-154-free-icons/" target="_blank"><img class="aligncenter size-full wp-image-1108" title="wpzoom-icon-set" src="http://www.intechgrity.com/wp-content/uploads/2012/05/wpzoom-icon-set.png" alt="" width="560" height="150" /></a><strong>Sizes:</strong> 48&#215;48 (<em>PSD included</em>) <strong>Total Icons:</strong> 154 <strong>Download: </strong><a href="http://www.wpzoom.com/wpzoom/new-freebie-wpzoom-developer-icon-set-154-free-icons/" target="_blank">Click here</a></p>
<h3 style="text-align: left;">#3: Mnml Icon Set</h3>
<p style="text-align: center;"><a href="http://brsev.deviantart.com/art/Mnml-Icon-Set-106367676" target="_blank"><img class="aligncenter size-full wp-image-1105" title="mnml-icon-set" src="http://www.intechgrity.com/wp-content/uploads/2012/05/mnml-icon-set.png" alt="" width="560" height="150" /></a><strong>Sizes:</strong> 128&#215;128 <strong>Total Icons:</strong> 32 <strong>Download: </strong><a href="http://brsev.deviantart.com/art/Mnml-Icon-Set-106367676" target="_blank">Click here</a></p>
<h3 style="text-align: left;">#4: Free Vector Icons</h3>
<p style="text-align: center;"><a href="http://www.dezinerfolio.com/freebie/30-free-vector-icons" target="_blank"><img class="aligncenter size-full wp-image-1100" title="free-vector-icons" src="http://www.intechgrity.com/wp-content/uploads/2012/05/free-vector-icons.png" alt="" width="560" height="150" /></a><strong>Sizes:</strong> Vectors (<em>PSD included</em>) <strong>Total Icons:</strong> 30 <strong>Download: </strong><a href="http://www.dezinerfolio.com/freebie/30-free-vector-icons" target="_blank">Click here</a></p>
<h3 style="text-align: left;">#5: Iconic Icon Set</h3>
<p style="text-align: center;"><a href="http://somerandomdude.com/work/iconic/" target="_blank"><img class="aligncenter size-full wp-image-1103" title="iconic-icon-set" src="http://www.intechgrity.com/wp-content/uploads/2012/05/iconic-icon-set.png" alt="" width="560" height="150" /></a><strong>Sizes:</strong> Vectors (<em>PSD, SVG included</em>) <strong>Total Icons:</strong> 171 <strong>Download: </strong><a href="http://somerandomdude.com/work/iconic/" target="_blank">Click here</a></p>
<h2 style="text-align: left;">Small Sized UI type icon:</h2>
<h3 style="text-align: left;">#6: Minicons Icon Set</h3>
<p style="text-align: center;"><a href="http://jospinoj.deviantart.com/art/minicons-292943928" target="_blank"><img class="aligncenter size-full wp-image-1104" title="minicons-icon-set" src="http://www.intechgrity.com/wp-content/uploads/2012/05/minicons-icon-set.png" alt="" width="550" height="150" /></a><strong>Sizes:</strong> Vectors (<em>PSD included</em>) <strong>Total Icons:</strong> 100+ <strong>Download: </strong><a href="http://jospinoj.deviantart.com/art/minicons-292943928" target="_blank">Click here</a></p>
<h3 style="text-align: left;">#7: Wireframe Toolbar Icons</h3>
<p style="text-align: center;"><a href="http://gentleface.com/free_icon_set.html" target="_blank"><img class="aligncenter size-full wp-image-1107" title="wireframe-icon-set" src="http://www.intechgrity.com/wp-content/uploads/2012/05/wireframe-icon-set.png" alt="" width="550" height="150" /></a><strong>Sizes:</strong> 16&#215;16, 24&#215;24, 32&#215;32, 48&#215;48 <strong>Total Icons: </strong>147 <strong>Download: </strong><a href="http://gentleface.com/free_icon_set.html" target="_blank">Click here</a></p>
<h3 style="text-align: left;">#8: Dusseldorf Icon Set</h3>
<p style="text-align: center;"><a href="http://pc.de/icons/#Dusseldorf" target="_blank"><img class="aligncenter size-full wp-image-1099" title="dusseldorf-icon-set" src="http://www.intechgrity.com/wp-content/uploads/2012/05/dusseldorf-icon-set.png" alt="" width="550" height="150" /></a><strong>Sizes:</strong> 16&#215;16, 32&#215;32, 48&#215;48 <strong>Total Icons: </strong>100+ <strong>Download: </strong><a href="http://pc.de/icons/#Dusseldorf" target="_blank">Click here</a></p>
<h3 style="text-align: left;">#9: Glyphish Icon Set</h3>
<p style="text-align: center;"><a href="http://glyphish.com/" target="_blank"><img class="aligncenter size-full wp-image-1102" title="glyphish-icon-set" src="http://www.intechgrity.com/wp-content/uploads/2012/05/glyphish-icon-set.png" alt="" width="550" height="150" /></a><strong>Sizes:</strong> 28&#215;28 (<em>PSD included</em>) <strong>Total Icons: </strong>100+ <strong>Download: </strong><a href="http://glyphish.com/" target="_blank">Click here</a></p>
<h3 style="text-align: left;">#10: Glyphicons Icon Set</h3>
<p style="text-align: center;"><a href="http://glyphicons.com/" target="_blank"><img class="aligncenter size-full wp-image-1101" title="glyphicons-icon-set" src="http://www.intechgrity.com/wp-content/uploads/2012/05/glyphicons-icon-set.png" alt="" width="550" height="150" /></a><strong>Sizes:</strong> 24&#215;24 <strong style="text-align: center;">Total Icons: </strong>400 <strong>Download: </strong><a href="http://glyphicons.com/" target="_blank">Click here</a></p>
<p style="text-align: left;">So that was all. If you are aware of something better, or wish to see your own icon sets in this list, do drop a comment.</p>
<p>Related posts:<ol>
<li><a href='http://www.intechgrity.com/15-free-web-icons-background/' rel='bookmark' title='15+ Free Web-Icons &amp; Background Patterns/Texture download sites to boost your Blog &amp; Website designing'>15+ Free Web-Icons &amp; Background Patterns/Texture download sites to boost your Blog &amp; Website designing</a></li>
<li><a href='http://www.intechgrity.com/huge-collection-of-css-js-jquery/' rel='bookmark' title='Huge collection of CSS, JS &amp; jQuery Dropdown Navigation menus for FREE &#124; Use on your Web site or Blog'>Huge collection of CSS, JS &amp; jQuery Dropdown Navigation menus for FREE &#124; Use on your Web site or Blog</a></li>
<li><a href='http://www.intechgrity.com/create-ajax-style-loading-animated-gif/' rel='bookmark' title='Create Ajax style Loading Animated Gif images easily with 3 Free Online Generators'>Create Ajax style Loading Animated Gif images easily with 3 Free Online Generators</a></li>
</ol></p><p>- By <a href="http://www.intechgrity.com">InTechgrity - Amalgamating Life &amp; Technology</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/greentechspot?a=0cdSI8PUwIE:5Ez12y9RKGI:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=0cdSI8PUwIE:5Ez12y9RKGI:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=0cdSI8PUwIE:5Ez12y9RKGI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=0cdSI8PUwIE:5Ez12y9RKGI:nQ_hWtDbxek"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=nQ_hWtDbxek" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=0cdSI8PUwIE:5Ez12y9RKGI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=0cdSI8PUwIE:5Ez12y9RKGI:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=0cdSI8PUwIE:5Ez12y9RKGI:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=0cdSI8PUwIE:5Ez12y9RKGI:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=0cdSI8PUwIE:5Ez12y9RKGI:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=0cdSI8PUwIE:5Ez12y9RKGI:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=0cdSI8PUwIE:5Ez12y9RKGI:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=0cdSI8PUwIE:5Ez12y9RKGI:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=0cdSI8PUwIE:5Ez12y9RKGI:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=0cdSI8PUwIE:5Ez12y9RKGI:YwkR-u9nhCs"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=YwkR-u9nhCs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=0cdSI8PUwIE:5Ez12y9RKGI:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=0cdSI8PUwIE:5Ez12y9RKGI:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=0cdSI8PUwIE:5Ez12y9RKGI:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=0cdSI8PUwIE:5Ez12y9RKGI:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=0cdSI8PUwIE:5Ez12y9RKGI:-BTjWOF_DHI" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/greentechspot/~4/0cdSI8PUwIE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.intechgrity.com/10-free-minimalist-grey-scale-icon-sets-for-your-web-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.intechgrity.com/10-free-minimalist-grey-scale-icon-sets-for-your-web-design/</feedburner:origLink></item>
		<item>
		<title>Howto: Choose the right web hosting company for your business</title>
		<link>http://feedproxy.google.com/~r/greentechspot/~3/Hpnqz_tqpXQ/</link>
		<comments>http://www.intechgrity.com/howto-choose-the-right-web-hosting-company-for-your-business/#comments</comments>
		<pubDate>Tue, 15 May 2012 10:43:41 +0000</pubDate>
		<dc:creator>Swashata</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Webhosts n Domains]]></category>
		<category><![CDATA[Web Hosting]]></category>

		<guid isPermaLink="false">http://www.intechgrity.com/?p=1072</guid>
		<description><![CDATA[<p><p>Original post published <a href="<a href="http://www.intechgrity.com/howto-choose-the-right-web-hosting-company-for-your-business/">Howto: Choose the right web hosting company for your business</a>">here</a></p><p>We have discussed a lot about web hosting and domains previously. One of the most important thing to consider while buying any web host is, undoubtedly, the value for money. Everyone wants to choose the right web hosting company for his/her business. Now, this is easy to say than to actually compare. With so many [...]</p></p><p>- By <a href="http://www.intechgrity.com">InTechgrity - Amalgamating Life &amp; Technology</a></p>
Related posts:<ol>
<li><a href='http://www.intechgrity.com/use-pickaweb-domain-hosting-to-buy/' rel='bookmark' title='Use PickaWeb Domain Hosting to buy Domains and Web Host at reasonable price'>Use PickaWeb Domain Hosting to buy Domains and Web Host at reasonable price</a></li>
<li><a href='http://www.intechgrity.com/choose-best-web-host-for-you-using/' rel='bookmark' title='Choose the Best Web Host for you using WebHostingGeeks.com'>Choose the Best Web Host for you using WebHostingGeeks.com</a></li>
<li><a href='http://www.intechgrity.com/choose-your-best-webhost-using/' rel='bookmark' title='Choose your Best Webhost using AlreadyHosting.com ~ One of the best webhosting review provider'>Choose your Best Webhost using AlreadyHosting.com ~ One of the best webhosting review provider</a></li>
<li><a href='http://www.intechgrity.com/best-and-affordable-alternatives-of/' rel='bookmark' title='The best and affordable alternatives of Google Page Hosting'>The best and affordable alternatives of Google Page Hosting</a></li>
<li><a href='http://www.intechgrity.com/host-your-website-using-one-of-uks-top/' rel='bookmark' title='Host your Website using one of UK’s top WebHosting sites-JustHost [review]'>Host your Website using one of UK’s top WebHosting sites-JustHost [review]</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/u8xmFMBoQueGy9OVAMAlsGuCj1E/0/da"><img src="http://feedads.g.doubleclick.net/~a/u8xmFMBoQueGy9OVAMAlsGuCj1E/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/u8xmFMBoQueGy9OVAMAlsGuCj1E/1/da"><img src="http://feedads.g.doubleclick.net/~a/u8xmFMBoQueGy9OVAMAlsGuCj1E/1/di" border="0" ismap="true"></img></a></p><p>Original post published <a href="<a href="http://www.intechgrity.com/howto-choose-the-right-web-hosting-company-for-your-business/">Howto: Choose the right web hosting company for your business</a>">here</a></p><p><a href="http://www.intechgrity.com/wp-content/uploads/2012/05/webhosting.png"><img class="alignright  wp-image-1081" title="webhosting" src="http://www.intechgrity.com/wp-content/uploads/2012/05/webhosting.png" alt="" width="250" height="250" /></a>We have discussed a lot about <a href="http://www.intechgrity.com/category/internet/webhosts-n-domains/">web hosting and domains</a> previously. One of the most important thing to consider while buying any web host is, undoubtedly, the <em>value for money</em>. Everyone wants to choose the right web hosting company for his/her business. Now, this is easy to say than to actually compare. With so many parameters of a reliable web host, so many features of a good web server, it just becomes difficult to choose among the &#8220;best&#8221;s. Luckily, there are services in the Internet which makes our job a lot easier. By looking into comparison tables, reading expert reviews and statistical analysis, going through highlighted features, we can get a better idea before putting money behind a web host. But still, you should have the basic (and well a little advanced won&#8217;t hurt) idea of today&#8217;s server technologies and cost for a profitable long term investment. So, we are going to discuss, what you need to consider before buying any web host. We shall also see some of the reviewing websites from where we can get aggregated information.</p>
<h2>Things to consider before buying:</h2>
<p>Out of my own experiences, I think, one should consider the following constrains while buying any web host:</p>
<h3><strong>#1: Offer Price &amp; Renewal Price:</strong></h3>
<p><a href="http://www.intechgrity.com/wp-content/uploads/2012/05/offer-price-renewal-price.png"><img class="aligncenter size-full wp-image-1077" title="offer-price-renewal-price" src="http://www.intechgrity.com/wp-content/uploads/2012/05/offer-price-renewal-price.png" alt="" width="550" height="150" /></a></p>
<p>The first thing that should come into mind is, indeed the money. After all you are investing something for your company, so you want to be sure that you get the maximum out of it! Most web hosting services out there offers very less price while buying, and then the renewal price becomes higher. Mostly people overlook this thing. We buy using some promo code and then after a year or two, when the renewal time comes, we have to spend rather a lot to continue the service.<strong></strong></p>
<h3><strong>#2: Specifications &amp; Features:</strong></h3>
<p><a href="http://www.intechgrity.com/wp-content/uploads/2012/05/specifications-features.png"><img class="aligncenter size-full wp-image-1079" title="specifications-features" src="http://www.intechgrity.com/wp-content/uploads/2012/05/specifications-features.png" alt="" width="550" height="150" /></a></p>
<p>The most concerned features and specs are, perhaps, diskspace, bandwidth and number of addon domains. The more number of addon domains you have, more number of sites you can host. So, you know that you not just put money behind a single website hosting, rather a multi website hosting. Now a days, most good web hosts give unlimited addon domains.</p>
<ul>
<li><strong>Technical Limitations:</strong> Apart from the unlimited stuffs, you should look into the technical limitations. Some host might give you unlimited bandwidth at the cost of limited domains and vice versa. Just keep in mind, what do you really need from your host.</li>
<li><strong>Domains, Addon Domains, Parked Domains &amp; Sub domains:</strong> The main domain is the domain which is registered primarily with your web host. The addon domains are other domains which you can add and host using the same web host. The parked domains are &#8220;parked&#8221; on some directory of your existing sites. If someone enters the URL of the parked domain, then it will show that directory (and the index file if present). Now sub domains are the children of your main domain. Say, you have<em> mydomain.com</em> as your main domain or addon domain. Then, <em>mysubdomain.mydomain.com</em> would be a sub domain. Now a days, no limits are imposed on all these, which means, with a good web host, you can host unlimited domains with unlimited sub-domains.</li>
<li><strong>Domain portability: </strong>Another thing you look into is, domain portability. Some hosts out there force you to register your domain with them. Personally, I don&#8217;t prefer to do business with such web hosting companies. What if I want to move my sites to another host? Web hosts which gives the flexibility to add your already registered domain via the name servers, are always my first preferences.</li>
<li><strong>Bandwidth:</strong> The bigger the value, more visitors your webhost can support. With unlimited bandwidth, this is not an issue in shared hosting. But if you are going for VPS or VPN or Cloud, then you should look into the bandwidth and consider it seriously with respect to the number of visitors in your site. An average site, with around 1500-2000 page visits per day, might consume upto 100GB per month, depending on the data provided by the site. (This figure is mainly for image heavy sites, a text heavy site will actually consume much less bandwidth). You can use tools like <a href="http://getfirebug.com/" target="_blank">Firebug</a> to check out the size of your pages and estimate average bandwidth by multiplying it with your daily average page visits.</li>
<li><strong>Disk Usage: </strong>Larger value indicates bigger possibilities for storing audio, video and image files. But also keep in mind that a nice disk usage limitation is useless without a nicer Bandwidth cap. So choose wisely. You won&#8217;t want to have a web host with 100 GB diskspace yet only 10 GB bandwidth per month.</li>
<li><strong>Server Technology: </strong>The technology depends explicitly on your requirement. If you want to publish a .net or aspx site, then you would prefer <em>Windows Hosting</em>. Where as, if you are familiar with Open source technologies like PHP, MySQL etc, then <em>Linux Hosting</em> should be your first choice. Some of you might want to have several other technologies like <em>Ruby on Rails, Perl, CGI</em> etc.</li>
<li><strong>Website builder and Auto Installer script:</strong> Now, not everyone of us buy a webhost to create their sites from scratch or install CMS at their own. There are services like <a href="http://www.softaculous.com/" target="_blank">softaculous</a>, <a href="https://netenberg.com/fantastico.php" target="_blank">fantastico</a> etc which makes our job even easier. They provide a one click installer for popular CMS like WordPress, Joomla etc. All of the good web hosts should provide atleast one of these auto-installer scripts.</li>
<li><strong>Emails &amp; Accounts:</strong> If you want to access your email directly within your host, this should be your concern. Personally, I prefer using <a title="Register your Domain with Google Apps – Beginners Tutorial on setting up the DNS part and URL forwarding" href="http://www.intechgrity.com/register-your-domain-with-google-apps/">google apps to setup my email accounts</a> for the domain. But this feature should not be overlooked.</li>
<li><strong>SSH Access: </strong>If you know what this feature is, then you probably want your web host to support your feature. For those, who doesn&#8217;t know, <a href="http://support.hostgator.com/articles/hosting-guide/lets-get-started/how-do-i-get-and-use-ssh-access" target="_blank">here</a> <a href="http://support.suso.com/supki/SSH_Tutorial_for_Linux" target="_blank">are</a> <a href="http://wtfh4x.wordpress.com/2010/11/27/25-useful-ssh-commands/" target="_blank">some</a> articles I found from the google explaining the importance and advantages of this feature. Note that for average usage, you won&#8217;t need this.</li>
</ul>
<h3><strong>#3: Server Performance &amp; Uptime:</strong></h3>
<p><a href="http://www.intechgrity.com/wp-content/uploads/2012/05/serveruptime.png"><img class="aligncenter size-full wp-image-1078" title="serveruptime" src="http://www.intechgrity.com/wp-content/uploads/2012/05/serveruptime.png" alt="" width="550" height="150" /></a></p>
<p>You don&#8217;t want your website to be down. There are already services which does the job for us. But in most of the times the information provided is bloated with just too many details. The thing which one should look while choosing a good web host, is, the average uptime for the target region. Which means, if your target visitors are from US, then obviously you should not come into any conclusion from the UK&#8217;s uptime.</p>
<h3>#4: Technical Support:</h3>
<p><a href="http://www.intechgrity.com/wp-content/uploads/2012/05/technical-support.png"><img class="aligncenter size-full wp-image-1080" title="technical-support" src="http://www.intechgrity.com/wp-content/uploads/2012/05/technical-support.png" alt="" width="550" height="150" /></a></p>
<p>The next most important thing, is perhaps, how much support and technical help your web host can give. Mostly, now a days, big web hosting companies like Hostgator, Fatcow, BlueHost etc, have their dedicated support forum for their customers. Also, they give 24X7 toll free numbers where you can call and easily get help, regardless of your location. So, you should consider this aspect as well. If your site goes down, then there should be someone to recover.</p>
<h3>#5: Compliance:</h3>
<p><a href="http://www.intechgrity.com/wp-content/uploads/2012/05/compliance.png"><img class="aligncenter size-full wp-image-1076" title="compliance" src="http://www.intechgrity.com/wp-content/uploads/2012/05/compliance.png" alt="" width="550" height="150" /></a></p>
<p>When you are using any external web host to host your site, then you should be aware of a few things. Because after all, it is your web host who is finally showing your site to the world. I would recommend to go through it at least once, before buying any web host. It is generally found at their Policy.</p>
<h2>Doing your own researches:</h2>
<p>Recently I was looking into fatcow and bluehost reviews in the internet. As an experienced blogger and developer, I am already aware of these two web hosting services and I used to think bluehost is any day better than its competitors because, it has spend more time in the business. But, surprisingly, my concepts changed as soon as I looked into those reviews. Here are the few of the points I noticed:</p>
<ul>
<li><a href="http://www.webhostingsearch.com/review/fatcow" target="_blank">Fatcow will give a 24 months plan at only $3.67/month</a> (at the time of the review). Now that&#8217;s quite a lot of saving. Whereas, for BlueHost it is $19.95/month (although it is for reseller plan, but I prefer to stick to normal plans).</li>
<li>For <a href="http://www.webhostingsearch.com/review/bluehost" target="_blank">bluehost, it is $19.94/month for reseller plan</a>. I could not found any offer on normal plans. They have 100GB diskspace, 15Mbps bandwidth, unlimited accounts, but they did not provide any easy to get information on bandwidth cap.</li>
<li>Fatcow gives free domain &amp; setup along with 75$ marketing credits. Also, just like bluehost it has unlimited addon domains along with unlimited diskspace and bandwidth.</li>
<li>User recommendation of Fatcows beats BlueHost by 35%. For big web hosting companies like this, 35% is really something to consider.</li>
</ul>
<p>So, from all these points, I could figure out that, had I wanted a reseller web host, I would have chosen BlueHost, but, as my needs are limited, so FatCow gives the best solution for me at a very reasonable, rather cheap price.</p>
<p>I hope you have found this review useful, and it will help you find the best web hosting for you. If you have any doubt, feel free to comment. I will be more than happy to help you.</p>
<p>Related posts:<ol>
<li><a href='http://www.intechgrity.com/use-pickaweb-domain-hosting-to-buy/' rel='bookmark' title='Use PickaWeb Domain Hosting to buy Domains and Web Host at reasonable price'>Use PickaWeb Domain Hosting to buy Domains and Web Host at reasonable price</a></li>
<li><a href='http://www.intechgrity.com/choose-best-web-host-for-you-using/' rel='bookmark' title='Choose the Best Web Host for you using WebHostingGeeks.com'>Choose the Best Web Host for you using WebHostingGeeks.com</a></li>
<li><a href='http://www.intechgrity.com/choose-your-best-webhost-using/' rel='bookmark' title='Choose your Best Webhost using AlreadyHosting.com ~ One of the best webhosting review provider'>Choose your Best Webhost using AlreadyHosting.com ~ One of the best webhosting review provider</a></li>
<li><a href='http://www.intechgrity.com/best-and-affordable-alternatives-of/' rel='bookmark' title='The best and affordable alternatives of Google Page Hosting'>The best and affordable alternatives of Google Page Hosting</a></li>
<li><a href='http://www.intechgrity.com/host-your-website-using-one-of-uks-top/' rel='bookmark' title='Host your Website using one of UK’s top WebHosting sites-JustHost [review]'>Host your Website using one of UK’s top WebHosting sites-JustHost [review]</a></li>
</ol></p><p>- By <a href="http://www.intechgrity.com">InTechgrity - Amalgamating Life &amp; Technology</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/greentechspot?a=Hpnqz_tqpXQ:yZVW8I9kUig:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=Hpnqz_tqpXQ:yZVW8I9kUig:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=Hpnqz_tqpXQ:yZVW8I9kUig:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=Hpnqz_tqpXQ:yZVW8I9kUig:nQ_hWtDbxek"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=nQ_hWtDbxek" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=Hpnqz_tqpXQ:yZVW8I9kUig:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=Hpnqz_tqpXQ:yZVW8I9kUig:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=Hpnqz_tqpXQ:yZVW8I9kUig:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=Hpnqz_tqpXQ:yZVW8I9kUig:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=Hpnqz_tqpXQ:yZVW8I9kUig:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=Hpnqz_tqpXQ:yZVW8I9kUig:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=Hpnqz_tqpXQ:yZVW8I9kUig:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=Hpnqz_tqpXQ:yZVW8I9kUig:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=Hpnqz_tqpXQ:yZVW8I9kUig:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=Hpnqz_tqpXQ:yZVW8I9kUig:YwkR-u9nhCs"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=YwkR-u9nhCs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=Hpnqz_tqpXQ:yZVW8I9kUig:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=Hpnqz_tqpXQ:yZVW8I9kUig:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=Hpnqz_tqpXQ:yZVW8I9kUig:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=Hpnqz_tqpXQ:yZVW8I9kUig:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=Hpnqz_tqpXQ:yZVW8I9kUig:-BTjWOF_DHI" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/greentechspot/~4/Hpnqz_tqpXQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.intechgrity.com/howto-choose-the-right-web-hosting-company-for-your-business/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.intechgrity.com/howto-choose-the-right-web-hosting-company-for-your-business/</feedburner:origLink></item>
		<item>
		<title>Login, Logout and Administrate using PHP SESSION, COOKIE &amp; MySQL – Version 2 with remember me option</title>
		<link>http://feedproxy.google.com/~r/greentechspot/~3/W4WCMKlEgIg/</link>
		<comments>http://www.intechgrity.com/login-logout-and-administrate-using-php-session-cookie-mysql-version-2-with-remember-me-option/#comments</comments>
		<pubDate>Fri, 11 May 2012 18:49:05 +0000</pubDate>
		<dc:creator>Swashata</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php-cookie]]></category>
		<category><![CDATA[php-post]]></category>
		<category><![CDATA[php-session]]></category>

		<guid isPermaLink="false">http://www.intechgrity.com/?p=1052</guid>
		<description><![CDATA[<p><p>Original post published <a href="<a href="http://www.intechgrity.com/login-logout-and-administrate-using-php-session-cookie-mysql-version-2-with-remember-me-option/">Login, Logout and Administrate using PHP SESSION, COOKIE &#038; MySQL &#8211; Version 2 with remember me option</a>">here</a></p><p>So, our last post on creating login admin and logout seems to be pretty backdated. We decided to come up with a new post under the same topic. So, to start with, let us see what you will be able to do after following this tutorial: Create a MySQL database for managing admin users. Use [...]</p></p><p>- By <a href="http://www.intechgrity.com">InTechgrity - Amalgamating Life &amp; Technology</a></p>
Related posts:<ol>
<li><a href='http://www.intechgrity.com/create-login-admin-logout-page-in-php-w/' rel='bookmark' title='Create Login Admin &amp; Logout Page in PHP w/ SESSION n MySQL'>Create Login Admin &amp; Logout Page in PHP w/ SESSION n MySQL</a></li>
<li><a href='http://www.intechgrity.com/get-parent-directory-of-current-url/' rel='bookmark' title='Get Parent directory of Current URL using PHP dirname function'>Get Parent directory of Current URL using PHP dirname function</a></li>
<li><a href='http://www.intechgrity.com/how-to-connect-to-xamppmysql-using/' rel='bookmark' title='How to Connect to XAMPP/MySQL using Windows CMD [Command Prompt]'>How to Connect to XAMPP/MySQL using Windows CMD [Command Prompt]</a></li>
<li><a href='http://www.intechgrity.com/jquery-recent-post-widget-for/' rel='bookmark' title='jQuery Recent Post Widget for BlogSpot/Blogger with Filter by Tag Option'>jQuery Recent Post Widget for BlogSpot/Blogger with Filter by Tag Option</a></li>
<li><a href='http://www.intechgrity.com/understanding-the-basic-of-html-form-and-php-get-and-post-method/' rel='bookmark' title='Understanding the basic of HTML form and PHP GET and POST method'>Understanding the basic of HTML form and PHP GET and POST method</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/ETXynK5-9AOKMoDyjOxRfkWtIJY/0/da"><img src="http://feedads.g.doubleclick.net/~a/ETXynK5-9AOKMoDyjOxRfkWtIJY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ETXynK5-9AOKMoDyjOxRfkWtIJY/1/da"><img src="http://feedads.g.doubleclick.net/~a/ETXynK5-9AOKMoDyjOxRfkWtIJY/1/di" border="0" ismap="true"></img></a></p><p>Original post published <a href="<a href="http://www.intechgrity.com/login-logout-and-administrate-using-php-session-cookie-mysql-version-2-with-remember-me-option/">Login, Logout and Administrate using PHP SESSION, COOKIE &#038; MySQL &#8211; Version 2 with remember me option</a>">here</a></p><p><a href="http://www.intechgrity.com/wp-content/uploads/2012/05/secured-login3.png"><img class="alignright size-medium wp-image-1057" title="secured login[3]" src="http://www.intechgrity.com/wp-content/uploads/2012/05/secured-login3-300x168.png" alt="" width="300" height="168" /></a>So, our last post on <a title="Create Login Admin &amp; Logout Page in PHP w/ SESSION n MySQL" href="http://www.intechgrity.com/create-login-admin-logout-page-in-php-w/" target="_blank">creating login admin and logout</a> seems to be pretty backdated. We decided to come up with a new post under the same topic. So, to start with, let us see what you will be able to do after following this tutorial:</p>
<ul>
<li>Create a MySQL database for managing admin users. Use SHA1 encryption method to store the password in database. Also insert data into it.</li>
<li>Create your own login/logout system in PHP using Cookie and Session along with remember me option. We shall md5 the SHA1 password in cookie for better protection.</li>
<li>Understand the PHP code behind the scene. How we have stored the encrypted password in the cookie.</li>
<li>Implementing the whole thing in OOP (Object Oriented Programming).</li>
</ul>
<p>In this tutorial we will do only the basic stuffs, there will be no CSS/HTML styling. In our next release, we will provide you a package with HTML5 admin, from where you can download and use it directly in your projects. This tutorial is intended to explain the basic mechanism used in Login Systems and how cookies and sessions work to provide the administrator security. We will discuss the file and directory structure, the database structure, we will see how we&#8217;ve used MySQL in PHP to connect to database and how we actually authenticate the user for a single session or for multiple session (in case the remember me option is selected). Check out below to get the codes straight away if you know how to do this already and just want to get the code.</p>
<div class="demo-download lonely"><a class="download" title="Login Logout System Downloaded 200" href="http://www.intechgrity.com/downloads/13">Download Now</a></div>
<p>As for the so called licensing stuffs, this whole thing is just <strong>FREE</strong>. You download, fork, modify, redistribute, use in your project, or do whatever you want. Although a credit will be appreciated, but in this open world of internet, it is completely upto you.</p>
<p>So, let us start with the directory structure and understand which file does what.</p>
<h2>#0: File and directory structure:</h2>
<p><a href="http://www.intechgrity.com/wp-content/uploads/2012/05/file-structure-login-logout.png"><img class="aligncenter size-full wp-image-1059" title="file-structure-login-logout" src="http://www.intechgrity.com/wp-content/uploads/2012/05/file-structure-login-logout.png" alt="" width="209" height="199" /></a></p>
<ul>
<li><strong>directory &#8211; admin: </strong>The root directory of all your admin files. It contains all the classes, login/logout files etc that we need to get the system running.
<ul>
<li><strong>admin-class.php</strong> &#8211; The main library class of the admin. It contains the several library functions that we need for user authentication, password checking etc.</li>
<li><strong>index.php</strong> &#8211; The main admin file which should be restricted to the logged in administrator only. If not logged in, then this should redirect to the login page.</li>
<li><strong>login-action.php</strong> &#8211; The action file which processes the user submitted username and password and authenticates on success. On failure, it redirects to the login page.</li>
<li><strong>login.php</strong> &#8211; The login form where users are asked to enter their username, password etc along with the a nice remember me option.</li>
<li><strong>logout.php</strong> &#8211; The logout script which should clear the authentication data and send back the user to the login page.</li>
</ul>
</li>
<li><strong>directory &#8211; db:</strong> The root directory for the database connection files. We have used <a href="http://justinvincent.com/ezsql" target="_blank">ezSQL</a>to code our application. It gives several query abstractions for faster access.
<ul>
<li><strong>db.php </strong>- It includes the library files <strong>ez_sql_core.php </strong>&amp; <strong>ez_sql_mysql.php</strong> and initializes a global variable <strong>$db</strong> for all the database connections. We shall look more about this later.</li>
<li><strong>ez_sql_core.php</strong> &#8211; The core ez_sql file as downloaded from the link above.</li>
<li><strong>ez_sql_mysql.php </strong>- The MySQL extension for the ezSQL.</li>
</ul>
</li>
</ul>
<h2>#1.1: Creating the database:</h2>
<p>We shall start by creating a new database for our application. If you are on linux and have MySQL installed, just open up terminal and hit <span class="code">mysql</span> (you need to access with super user privilege if you have not changed the mysql root, <span class="code">su mysql</span> or <span class="code">sudo mysql</span>) and enter the following sql queries.</p>
<p><a href="http://www.intechgrity.com/wp-content/uploads/2012/05/database-login-logout.png"><img class="aligncenter size-medium wp-image-1060" title="database-login-logout" src="http://www.intechgrity.com/wp-content/uploads/2012/05/database-login-logout-300x190.png" alt="" width="300" height="190" /></a></p>
<pre class="brush: sql; title: ; notranslate">
CREATE DATABASE login_test;
USE login_test;

CREATE TABLE `user` (
`id` INT NOT NULL auto_increment,
`username` VARCHAR(50) NOT NULL default '',
`nicename` VARCHAR(255) NOT NULL default '',
`email` VARCHAR(255) NOT NULL default '',
`password` VARCHAR(255) NOT NULL default '',
UNIQUE KEY `user_n` (`username`),
UNIQUE KEY `user_e` (`email`),
    PRIMARY KEY (`id`)
);

INSERT INTO `user` (`username`, `nicename`, `email`, `password`)
VALUES (
'swashata', 'Swashata Ghosh', 'abc@domain.com', SHA1('pass')
);
</pre>
<p><a href="http://www.intechgrity.com/wp-content/uploads/2012/05/database-table-login-logout.png"><img class="aligncenter size-medium wp-image-1061" title="database-table-login-logout" src="http://www.intechgrity.com/wp-content/uploads/2012/05/database-table-login-logout-300x257.png" alt="" width="300" height="257" /></a></p>
<p>Let us see what it does:</p>
<ol>
<li>Creates a database named <span class="spanlight">login_test</span>.</li>
<li>Use that database.</li>
<li>Create a table <span class="spanlight">user</span> with id, username, nicename, email and password as fields. Set usename and email as unique keys and id as primary key.</li>
<li> Insert a user named swashata with nicename Swashata Ghosh, email as above and password as pass.</li>
<li>Note that we have encrypted the password &#8216;<span class="spanlight">pass</span>&#8216; using the SHA1 encryption method provided my MySQL. In this way our password is stored in encrypted form. But that also means, you will never be able to see it in original form again. So, how do you reset it? Simple, by querying the database directly. Just</li>
</ol>
<p>Now, if you run a SELECT * query, then you will see something like this.</p>
<p>All done, now let us code the PHP backend.</p>
<h2>#1.2: Connecting the database with PHP: &#8211; db.php</h2>
<p>Now, we need to connect this database to our script. To do this, we will be using ezSQL as mentioned before. So, inside our db.php file, we place the following code:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
* The db.php file which initiates a connection to the database
* and gives a global $db variable for access
* @author Swashata &lt;swashata@intechgrity.com&gt;
* @uses ezSQL MySQL
*/
/** edit your configuration */
$dbuser = 'db_user';
$dbname = 'db_name';
$dbpassword = 'db_password';
$dbhost = 'localhost';

/** Stop editing from here, else you know what you are doing <img src='http://www.intechgrity.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  */

/** defined the root for the db */
if(!defined('ADMIN_DB_DIR'))
define('ADMIN_DB_DIR', dirname(__FILE__));

require_once ADMIN_DB_DIR . '/ez_sql_core.php';
require_once ADMIN_DB_DIR . '/ez_sql_mysql.php';
global $db;
$db = new ezSQL_mysql($dbuser, $dbpassword, $dbname, $dbhost);
</pre>
<p>As you can see, it creates a global $db object which connects to the database from the credential above. To use it, we just need to include this file and declare $db as global.</p>
<h2>#2: Creating the Login form: &#8211; login.php</h2>
<p>So, we have used a plain and simple login form with valid xhtml markup. You can add your own css to it to make it look better. The things to notice are</p>
<ul>
<li>The name and id of the fields should not change.</li>
<li>The form method should be post and action should be login-action.php.</li>
</ul>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
    &lt;head&gt;
        &lt;title&gt;Login to admin&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;form action=&quot;login-action.php&quot; method=&quot;post&quot;&gt;
            &lt;fieldset&gt;
                &lt;legend&gt;Enter Credential&lt;/legend&gt;
                    &lt;p&gt;
                        &lt;label for=&quot;username&quot;&gt;Username: &lt;/label&gt;
                        &lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;username&quot; value=&quot;&quot; /&gt;
                    &lt;/p&gt;
                    &lt;p&gt;
                        &lt;label for=&quot;password&quot;&gt;Password: &lt;/label&gt;
                        &lt;input type=&quot;password&quot; name=&quot;password&quot; id=&quot;password&quot; value=&quot;&quot; /&gt;
                    &lt;/p&gt;
                    &lt;p&gt;
                        &lt;label for=&quot;remember&quot;&gt;
                            &lt;input type=&quot;checkbox&quot; name=&quot;remember&quot; id=&quot;remember&quot; value=&quot;1&quot; /&gt; Remember me
                        &lt;/label&gt;
                    &lt;/p&gt;
            &lt;/fieldset&gt;
            &lt;p&gt;
                &lt;input type=&quot;submit&quot; value=&quot;Submit&quot; /&gt; &lt;input type=&quot;reset&quot; value=&quot;Reset&quot; /&gt;
            &lt;/p&gt;
        &lt;/form&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Simple and effective.</p>
<h2>#3: Creating the library classes &#8211; admin-class.php</h2>
<p>We first need to analyze what features we need for our library. The basic features are (and also the code behind it):</p>
<p>#3.0: Initialize the session for login system:</p>
<p>Login systems work mainly either on session or on cookie. As we are using remember me option, so it is better to use both. Here is how we initialize the session and do some other stuffs.</p>
<pre class="brush: php; title: ; notranslate">
    /**
     * The constructor function of admin class
     * We do just the session start
     * It is necessary to start the session before actually storing any value
     * to the super global $_SESSION variable
     */
    public function __construct() {
        session_start();

        //store the absolute script directory
        //note that this is not the admin directory
        self::$abs_path = dirname(dirname(__FILE__));

        //initialize the post variable
        if($_SERVER['REQUEST_METHOD'] == 'POST') {
            $this-&gt;post = $_POST;
            if(get_magic_quotes_gpc ()) {
                //get rid of magic quotes and slashes if present
                array_walk_recursive($this-&gt;post, array($this, 'stripslash_gpc'));
            }
        }

        //initialize the get variable
        $this-&gt;get = $_GET;
        //decode the url
        array_walk_recursive($this-&gt;get, array($this, 'urldecode'));
    }
</pre>
<h3>#3.1: Checking the database for valid username and password combination:</h3>
<pre class="brush: php; title: ; notranslate">
    /**
     * Check the database for login user
     * Get the password for the user
     * compare md5 hash over sha1
     * @param string $username Raw username
     * @param string $password expected to be md5 over sha1
     * @return bool TRUE on success FALSE otherwise
     */
    private function _check_db($username, $password) {
        global $db;
        $user_row = $db-&gt;get_row(&quot;SELECT * FROM `user` WHERE `username`='&quot; . $db-&gt;escape($username) . &quot;'&quot;);

        //general return
        if(is_object($user_row) &amp;&amp; md5($user_row-&gt;password) == $password)
            return true;
        else
            return false;
    }
</pre>
<p>So, what we do is, we compare the <span class="code">md5</span> and <span class="code">sha1</span> encrypted password with the one stored in database. As the database has only sha1 encrypted password, so we calculate the md5 hash by passing it through the function md5. If it matches, then we return true else, false. You might think, from where we get the username and password. Just keep on reading.</p>
<h2>#3.2: Add action for the login-action.php file:</h2>
<pre class="brush: php; title: ; notranslate">
    /**
     * Check for login in the action file
     */
    public function _login_action() {

        //insufficient data provided
        if(!isset($this-&gt;post['username']) || $this-&gt;post['username'] == '' || !isset($this-&gt;post['password']) || $this-&gt;post['password'] == '') {
            header (&quot;location: login.php&quot;);
        }

        //get the username and password
        $username = $this-&gt;post['username'];
        $password = md5(sha1($this-&gt;post['password']));

        //check the database for username
        if($this-&gt;_check_db($username, $password)) {
            //ready to login
            $_SESSION['admin_login'] = $username;

            //check to see if remember, ie if cookie
            if(isset($this-&gt;post['remember'])) {
                //set the cookies for 1 day, ie, 1*24*60*60 secs
                //change it to something like 30*24*60*60 to remember user for 30 days
                setcookie('username', $username, time() + 1*24*60*60);
                setcookie('password', $password, time() + 1*24*60*60);
            } else {
                //destroy any previously set cookie
                setcookie('username', '', time() - 1*24*60*60);
                setcookie('password', '', time() - 1*24*60*60);
            }

            header(&quot;location: index.php&quot;);
        }
        else {
            header (&quot;location: login.php&quot;);
        }

        die();
    }
</pre>
<p>What it does is, calls the <span class="code">_check_db</span> function with the username and encrypted password as parameters. If true is returned, then it sets the session for the admin with the username as <span class="code">$_SESSION['admin_login']</span> variable. Then it further checks for remember me option, and if yes, then it sets cookie as well. We shall discuss more about cookie in some other post. For now, you can just check the comments. As it says, it stores the username and password in the corresponding variables for 1 day. To fetch the cookie we shall use <span class="code">$_COOKIE</span> super global.</p>
<h3>#3.3: Creating the authentication method:</h3>
<pre class="brush: php; title: ; notranslate">
    /**
     * Checks whether the user is authenticated
     * to access the admin page or not.
     *
     * Redirects to the login.php page, if not authenticates
     * otherwise continues to the page
     *
     * @access public
     * @return void
     */
    public function _authenticate() {
        //first check whether session is set or not
        if(!isset($_SESSION['admin_login'])) {
            //check the cookie
            if(isset($_COOKIE['username']) &amp;&amp; isset($_COOKIE['password'])) {
                //cookie found, is it really someone from the
                if($this-&gt;_check_db($_COOKIE['username'], $_COOKIE['password'])) {
                    $_SESSION['admin_login'] = $_COOKIE['username'];
                    header(&quot;location: index.php&quot;);
                    die();
                }
                else {
                    header(&quot;location: login.php&quot;);
                    die();
                }
            }
            else {
                header(&quot;location: login.php&quot;);
                die();
            }
        }
    }
</pre>
<p>When ever we need to authenticate in a file access, we just have to call this function. We shall see it in the index.php file. It automatically fetches the data from cookie, revalidates it and also redirects to the login.php in case of failure. This is just pretty much what you need.</p>
<p>#3.4: Putting together the class file &#8211; admin-class.php</p>
<pre class="brush: php; collapse: true; light: false; title: ; toolbar: true; notranslate">
&lt;?php
/** Include the database file */
include_once '../db/db.php';
/**
 * The main class of login
 * All the necesary system functions are prefixed with _
 * examples, _login_action - to be used in the login-action.php file
 * _authenticate - to be used in every file where admin restriction is to be inherited etc...
 * @author Swashata &lt;swashata@intechgrity.com&gt;
 */
class itg_admin {

    /**
     * Holds the script directory absolute path
     * @staticvar
     */
    static $abs_path;

    /**
     * Store the sanitized and slash escaped value of post variables
     * @var array
     */
    var $post = array();

    /**
     * Stores the sanitized and decoded value of get variables
     * @var array
     */
    var $get = array();

    /**
     * The constructor function of admin class
     * We do just the session start
     * It is necessary to start the session before actually storing any value
     * to the super global $_SESSION variable
     */
    public function __construct() {
        session_start();

        //store the absolute script directory
        //note that this is not the admin directory
        self::$abs_path = dirname(dirname(__FILE__));

        //initialize the post variable
        if($_SERVER['REQUEST_METHOD'] == 'POST') {
            $this-&gt;post = $_POST;
            if(get_magic_quotes_gpc ()) {
                //get rid of magic quotes and slashes if present
                array_walk_recursive($this-&gt;post, array($this, 'stripslash_gpc'));
            }
        }

        //initialize the get variable
        $this-&gt;get = $_GET;
        //decode the url
        array_walk_recursive($this-&gt;get, array($this, 'urldecode'));
    }

    /**
     * Sample function to return the nicename of currently logged in admin
     * @global ezSQL_mysql $db
     * @return string The nice name of the user
     */
    public function get_nicename() {
        $username = $_SESSION['admin_login'];
        global $db;
        $info = $db-&gt;get_row(&quot;SELECT `nicename` FROM `user` WHERE `username` = '&quot; . $db-&gt;escape($username) . &quot;'&quot;);
        if(is_object($info))
            return $info-&gt;nicename;
        else
            return '';
    }

    /**
     * Sample function to return the email of currently logged in admin user
     * @global ezSQL_mysql $db
     * @return string The email of the user
     */
    public function get_email() {
        $username = $_SESSION['admin_login'];
        global $db;
        $info = $db-&gt;get_row(&quot;SELECT `email` FROM `user` WHERE `username` = '&quot; . $db-&gt;escape($username) . &quot;'&quot;);
        if(is_object($info))
            return $info-&gt;email;
        else
            return '';
    }

    /**
     * Checks whether the user is authenticated
     * to access the admin page or not.
     *
     * Redirects to the login.php page, if not authenticates
     * otherwise continues to the page
     *
     * @access public
     * @return void
     */
    public function _authenticate() {
        //first check whether session is set or not
        if(!isset($_SESSION['admin_login'])) {
            //check the cookie
            if(isset($_COOKIE['username']) &amp;&amp; isset($_COOKIE['password'])) {
                //cookie found, is it really someone from the
                if($this-&gt;_check_db($_COOKIE['username'], $_COOKIE['password'])) {
                    $_SESSION['admin_login'] = $_COOKIE['username'];
                    header(&quot;location: index.php&quot;);
                    die();
                }
                else {
                    header(&quot;location: login.php&quot;);
                    die();
                }
            }
            else {
                header(&quot;location: login.php&quot;);
                die();
            }
        }
    }

    /**
     * Check for login in the action file
     */
    public function _login_action() {

        //insufficient data provided
        if(!isset($this-&gt;post['username']) || $this-&gt;post['username'] == '' || !isset($this-&gt;post['password']) || $this-&gt;post['password'] == '') {
            header (&quot;location: login.php&quot;);
        }

        //get the username and password
        $username = $this-&gt;post['username'];
        $password = md5(sha1($this-&gt;post['password']));

        //check the database for username
        if($this-&gt;_check_db($username, $password)) {
            //ready to login
            $_SESSION['admin_login'] = $username;

            //check to see if remember, ie if cookie
            if(isset($this-&gt;post['remember'])) {
                //set the cookies for 1 day, ie, 1*24*60*60 secs
                //change it to something like 30*24*60*60 to remember user for 30 days
                setcookie('username', $username, time() + 1*24*60*60);
                setcookie('password', $password, time() + 1*24*60*60);
            } else {
                //destroy any previously set cookie
                setcookie('username', '', time() - 1*24*60*60);
                setcookie('password', '', time() - 1*24*60*60);
            }

            header(&quot;location: index.php&quot;);
        }
        else {
            header (&quot;location: login.php&quot;);
        }

        die();
    }

    /**
     * Check the database for login user
     * Get the password for the user
     * compare md5 hash over sha1
     * @param string $username Raw username
     * @param string $password expected to be md5 over sha1
     * @return bool TRUE on success FALSE otherwise
     */
    private function _check_db($username, $password) {
        global $db;
        $user_row = $db-&gt;get_row(&quot;SELECT * FROM `user` WHERE `username`='&quot; . $db-&gt;escape($username) . &quot;'&quot;);

        //general return
        if(is_object($user_row) &amp;&amp; md5($user_row-&gt;password) == $password)
            return true;
        else
            return false;
    }

    /**
     * stripslash gpc
     * Strip the slashes from a string added by the magic quote gpc thingy
     * @access protected
     * @param string $value
     */
    private function stripslash_gpc(&amp;$value) {
        $value = stripslashes($value);
    }

    /**
     * htmlspecialcarfy
     * Encodes string's special html characters
     * @access protected
     * @param string $value
     */
    private function htmlspecialcarfy(&amp;$value) {
        $value = htmlspecialchars($value);
    }

    /**
     * URL Decode
     * Decodes a URL Encoded string
     * @access protected
     * @param string $value
     */
    protected function urldecode(&amp;$value) {
        $value = urldecode($value);
    }
}
</pre>
<h2>#4: Creating the login-action.php file:</h2>
<p>As we have everything in our class, so creating the login-action.php file will be a breeze. All what we do is</p>
<ul>
<li>Include the admin-class.php file.</li>
<li>Initiate a new instance of the itg_admin class.</li>
<li>Call the <span class="code">_login_action</span> function.</li>
</ul>
<pre class="brush: php; title: ; notranslate">
&lt;?php
include_once 'admin-class.php';
$admin = new itg_admin();
$admin-&gt;_login_action();
</pre>
<p>and we are done.</p>
<h2>#5: Creating the index.php file &#8211; restricted access:</h2>
<p>So, it is time to put all the codes to work. In index.php file we simply do what we have done in login-action.php file, except of calling the _login_action, we call <span class="code">_authenticate</span> function. It will automatically check whether user is authenticated to access the further script or not and will redirect to login form if necessary.</p>
<pre class="brush: php; html-script: true; title: ; notranslate">
&lt;?php
include_once 'admin-class.php';
$admin = new itg_admin();
$admin-&gt;_authenticate();
?&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
    &lt;head&gt;
        &lt;title&gt;Administrator page&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;fieldset&gt;
            &lt;legend&gt;Welcome &lt;?php echo $admin-&gt;get_nicename(); ?&gt;&lt;/legend&gt;
                &lt;p&gt;
                    Here are some of the basic informations
                &lt;/p&gt;
                &lt;p&gt;
                    Username: &lt;?php echo $_SESSION['admin_login']; ?&gt;
                &lt;/p&gt;
                &lt;p&gt;
                    Email: &lt;?php echo $admin-&gt;get_email(); ?&gt;
                &lt;/p&gt;
        &lt;/fieldset&gt;
        &lt;p&gt;
            &lt;input type=&quot;button&quot; onclick=&quot;javascript:window.location.href='logout.php'&quot; value=&quot;logout&quot; /&gt;
        &lt;/p&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre>
<p>and finally&#8230;</p>
<h2>#6: The logout.php file:</h2>
<p>Everything seems to be incomplete without it! What we do is</p>
<ul>
<li>Destroy the session.</li>
<li>Expire the cookie.</li>
<li>Redirect to login form.</li>
</ul>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
* The logout file
* destroys the session
* expires the cookie
* redirects to login.php
*/
session_start();
session_destroy();
setcookie('username', '', time() - 1*24*60*60);
setcookie('password', '', time() - 1*24*60*60);
header(&quot;location: login.php&quot;);
?&gt;
</pre>
<p>and we are done. It looks like this</p>
<p><a href="http://www.intechgrity.com/wp-content/uploads/2012/05/login-page.png"><img class="aligncenter size-medium wp-image-1063" title="login-page" src="http://www.intechgrity.com/wp-content/uploads/2012/05/login-page-300x176.png" alt="" width="300" height="176" /></a></p>
<p><a href="http://www.intechgrity.com/wp-content/uploads/2012/05/admin-page.png"><img class="aligncenter size-medium wp-image-1062" title="admin-page" src="http://www.intechgrity.com/wp-content/uploads/2012/05/admin-page-300x173.png" alt="" width="300" height="173" /></a></p>
<p>So that was all. Feel free to ask any questions you have. I will try best to answer them.</p>
<p>Related posts:<ol>
<li><a href='http://www.intechgrity.com/create-login-admin-logout-page-in-php-w/' rel='bookmark' title='Create Login Admin &amp; Logout Page in PHP w/ SESSION n MySQL'>Create Login Admin &amp; Logout Page in PHP w/ SESSION n MySQL</a></li>
<li><a href='http://www.intechgrity.com/get-parent-directory-of-current-url/' rel='bookmark' title='Get Parent directory of Current URL using PHP dirname function'>Get Parent directory of Current URL using PHP dirname function</a></li>
<li><a href='http://www.intechgrity.com/how-to-connect-to-xamppmysql-using/' rel='bookmark' title='How to Connect to XAMPP/MySQL using Windows CMD [Command Prompt]'>How to Connect to XAMPP/MySQL using Windows CMD [Command Prompt]</a></li>
<li><a href='http://www.intechgrity.com/jquery-recent-post-widget-for/' rel='bookmark' title='jQuery Recent Post Widget for BlogSpot/Blogger with Filter by Tag Option'>jQuery Recent Post Widget for BlogSpot/Blogger with Filter by Tag Option</a></li>
<li><a href='http://www.intechgrity.com/understanding-the-basic-of-html-form-and-php-get-and-post-method/' rel='bookmark' title='Understanding the basic of HTML form and PHP GET and POST method'>Understanding the basic of HTML form and PHP GET and POST method</a></li>
</ol></p><p>- By <a href="http://www.intechgrity.com">InTechgrity - Amalgamating Life &amp; Technology</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/greentechspot?a=W4WCMKlEgIg:YucjlmcGfoc:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=W4WCMKlEgIg:YucjlmcGfoc:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=W4WCMKlEgIg:YucjlmcGfoc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=W4WCMKlEgIg:YucjlmcGfoc:nQ_hWtDbxek"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=nQ_hWtDbxek" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=W4WCMKlEgIg:YucjlmcGfoc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=W4WCMKlEgIg:YucjlmcGfoc:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=W4WCMKlEgIg:YucjlmcGfoc:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=W4WCMKlEgIg:YucjlmcGfoc:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=W4WCMKlEgIg:YucjlmcGfoc:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=W4WCMKlEgIg:YucjlmcGfoc:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=W4WCMKlEgIg:YucjlmcGfoc:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=W4WCMKlEgIg:YucjlmcGfoc:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=W4WCMKlEgIg:YucjlmcGfoc:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=W4WCMKlEgIg:YucjlmcGfoc:YwkR-u9nhCs"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=YwkR-u9nhCs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=W4WCMKlEgIg:YucjlmcGfoc:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=W4WCMKlEgIg:YucjlmcGfoc:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=W4WCMKlEgIg:YucjlmcGfoc:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=W4WCMKlEgIg:YucjlmcGfoc:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=W4WCMKlEgIg:YucjlmcGfoc:-BTjWOF_DHI" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/greentechspot/~4/W4WCMKlEgIg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.intechgrity.com/login-logout-and-administrate-using-php-session-cookie-mysql-version-2-with-remember-me-option/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.intechgrity.com/login-logout-and-administrate-using-php-session-cookie-mysql-version-2-with-remember-me-option/</feedburner:origLink></item>
		<item>
		<title>WP Category Post List version 2 released</title>
		<link>http://feedproxy.google.com/~r/greentechspot/~3/KCI3R9bUg9o/</link>
		<comments>http://www.intechgrity.com/wp-category-post-list-version-2-released/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 14:04:46 +0000</pubDate>
		<dc:creator>Swashata</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[iTg WP Plugin News]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://www.intechgrity.com/?p=990</guid>
		<description><![CDATA[<p><p>Original post published <a href="<a href="http://www.intechgrity.com/wp-category-post-list-version-2-released/">WP Category Post List version 2 released</a>">here</a></p><p>So after around one year of first release, I finally came up with the 2nd version of the 5 star rated WordPress Category Post List plugin. As you have already guessed, there are plenty of new features in the WP-CPL V2. I have added excerpt option along with shortcode to fulfill everyone&#8217;s need. It is [...]</p></p><p>- By <a href="http://www.intechgrity.com">InTechgrity - Amalgamating Life &amp; Technology</a></p>
Related posts:<ol>
<li><a href='http://www.intechgrity.com/wp-category-post-list-plugin-list-your-posts-filtered-by-categories-with-thumbnails/' rel='bookmark' title='WP Category Post List Plugin &#8211; List your posts filtered by categories with thumbnails'>WP Category Post List Plugin &#8211; List your posts filtered by categories with thumbnails</a></li>
<li><a href='http://www.intechgrity.com/setting-post-thumbnail-on-wordpress-with-custom-size-and-cropping-a-simpler-approach/' rel='bookmark' title='Setting Post Thumbnail on WordPress with custom size and Cropping &#8211; A simpler approach'>Setting Post Thumbnail on WordPress with custom size and Cropping &#8211; A simpler approach</a></li>
<li><a href='http://www.intechgrity.com/getting-post-thumbnail-on-wordpress-3-w-wo-specific-post-id/' rel='bookmark' title='Getting Post thumbnail on WordPress 3 w/ w/o specific Post ID'>Getting Post thumbnail on WordPress 3 w/ w/o specific Post ID</a></li>
<li><a href='http://www.intechgrity.com/safari-web-browser-hits-version-4-new/' rel='bookmark' title='Safari Web browser hits version 4 ~ New Tabs and even Win7 AeroPeek compatibility'>Safari Web browser hits version 4 ~ New Tabs and even Win7 AeroPeek compatibility</a></li>
<li><a href='http://www.intechgrity.com/move-intense-debate-comment-from-blogger-to-wordpress-using-export-xml/' rel='bookmark' title='Move Intense Debate Comment from Blogger to WordPress using Export XML ~ First WP plugin by iTg'>Move Intense Debate Comment from Blogger to WordPress using Export XML ~ First WP plugin by iTg</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/EChWaj0hBjsp_R86e5Rbu0f3HQ8/0/da"><img src="http://feedads.g.doubleclick.net/~a/EChWaj0hBjsp_R86e5Rbu0f3HQ8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/EChWaj0hBjsp_R86e5Rbu0f3HQ8/1/da"><img src="http://feedads.g.doubleclick.net/~a/EChWaj0hBjsp_R86e5Rbu0f3HQ8/1/di" border="0" ismap="true"></img></a></p><p>Original post published <a href="<a href="http://www.intechgrity.com/wp-category-post-list-version-2-released/">WP Category Post List version 2 released</a>">here</a></p><p style="text-align: justify;"><a href="http://www.intechgrity.com/wp-plugins/wp-category-post-list-wordpress-plugin/"><img class="size-full wp-image-991 aligncenter" title="logo-wp-cpl-v2" src="http://www.intechgrity.com/wp-content/uploads/2012/02/logo-wp-cpl-v2.png" alt="" width="500" height="300" /></a>So after around one year of first release, I finally came up with the 2nd version of the 5 star rated WordPress Category Post List plugin. As you have already guessed, there are plenty of new features in the WP-CPL V2. I have added excerpt option along with shortcode to fulfill everyone&#8217;s need. It is needless to say, the current version is far better than the previous version. Due to hefty amount of added features, I gave it a V2 tag. Some of you might have noticed that version 1.1.0 was there in development trac but it never got released. Finally after compiling a long list of @todo tags, the version 2 is out in the wild.</p>
<p style="text-align: justify;"><div class='et-box et-warning'>
					<div class='et-box-content'>Version 2.0.2 has been released with bugfix for WP auto upgrade and no css theme selection error. Please upgrade immediately if you are still at version 2.0.0</div></div></p>
<p>Here are the new features at a glance&#8230;</p>
<h2>New Features in V2:</h2>
<ul>
<li><strong>Shortcode</strong>: The most awaited feature of WP-CPL. Now you can use shortcodes to display a full featured list of category filtered posts</li>
<li><strong>Multi theme capability</strong>: Unlike version 1, you can add multiple themes to the multiple instances of widgets or shortcodes. For widgets you can simply select the active theme from the dropdown and for shortcodes, you need to enter the id of the css theme.</li>
<li><strong>More widget configuration</strong>: Added options for displaying <em>author, date</em> etc. Now supports full HTML compatible <strong><em>Read more &amp; Feed </em></strong>anchor.</li>
<li><strong>Excerpt</strong>: The second most demanding feature. You can now not only show hardcoded excerpts but also can generate length specified excerpts from post contents.</li>
<li><strong>Auto Detect category</strong>: As requested by many users, the widget now holds an option to automatically detect the current category of the post and list other posts accordingly. If it is homepage or no category is found, the widget output is suspended.</li>
</ul>
<h2>Under the hood development:</h2>
<ul>
<li>Completely changed the code structure. The whole plugin is now coded in Object Oriented structure.</li>
<li>Added filters for inserting your own CSS theme to the list. For more check the plugin page.</li>
<li>Version information now saved via the plugin option. So future upgrade will be smoother.</li>
<li>Merged widget theme with the shortcode theme. Also tweaked some CSS to make the themes look a bit better.</li>
<li>Images on the plugin&#8217;s settings page are now loaded locally. We have changed this as per the specification of <a href="http://wordpress.org/extend/plugins/about/guidelines/">WP Plugin standards</a> (#7).</li>
</ul>
<p>That will be all to summarize the release of version 2. Make sure to check the <a title="WP Category Post List – WordPress Plugin" href="http://www.intechgrity.com/wp-plugins/wp-category-post-list-wordpress-plugin/">documentation page here</a>. Also, you can jump straight to the <a title="Jump to wordpress extend page" href="http://wordpress.org/extend/plugins/wp-category-posts-list/">WordPress extend page</a> to download and start using this plugin. <strong><em>Don&#8217;t forget to give your feedback</em></strong>.</p>
<p>Related posts:<ol>
<li><a href='http://www.intechgrity.com/wp-category-post-list-plugin-list-your-posts-filtered-by-categories-with-thumbnails/' rel='bookmark' title='WP Category Post List Plugin &#8211; List your posts filtered by categories with thumbnails'>WP Category Post List Plugin &#8211; List your posts filtered by categories with thumbnails</a></li>
<li><a href='http://www.intechgrity.com/setting-post-thumbnail-on-wordpress-with-custom-size-and-cropping-a-simpler-approach/' rel='bookmark' title='Setting Post Thumbnail on WordPress with custom size and Cropping &#8211; A simpler approach'>Setting Post Thumbnail on WordPress with custom size and Cropping &#8211; A simpler approach</a></li>
<li><a href='http://www.intechgrity.com/getting-post-thumbnail-on-wordpress-3-w-wo-specific-post-id/' rel='bookmark' title='Getting Post thumbnail on WordPress 3 w/ w/o specific Post ID'>Getting Post thumbnail on WordPress 3 w/ w/o specific Post ID</a></li>
<li><a href='http://www.intechgrity.com/safari-web-browser-hits-version-4-new/' rel='bookmark' title='Safari Web browser hits version 4 ~ New Tabs and even Win7 AeroPeek compatibility'>Safari Web browser hits version 4 ~ New Tabs and even Win7 AeroPeek compatibility</a></li>
<li><a href='http://www.intechgrity.com/move-intense-debate-comment-from-blogger-to-wordpress-using-export-xml/' rel='bookmark' title='Move Intense Debate Comment from Blogger to WordPress using Export XML ~ First WP plugin by iTg'>Move Intense Debate Comment from Blogger to WordPress using Export XML ~ First WP plugin by iTg</a></li>
</ol></p><p>- By <a href="http://www.intechgrity.com">InTechgrity - Amalgamating Life &amp; Technology</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/greentechspot?a=KCI3R9bUg9o:CcX-4mgWvbU:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=KCI3R9bUg9o:CcX-4mgWvbU:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=KCI3R9bUg9o:CcX-4mgWvbU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=KCI3R9bUg9o:CcX-4mgWvbU:nQ_hWtDbxek"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=nQ_hWtDbxek" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=KCI3R9bUg9o:CcX-4mgWvbU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=KCI3R9bUg9o:CcX-4mgWvbU:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=KCI3R9bUg9o:CcX-4mgWvbU:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=KCI3R9bUg9o:CcX-4mgWvbU:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=KCI3R9bUg9o:CcX-4mgWvbU:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=KCI3R9bUg9o:CcX-4mgWvbU:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=KCI3R9bUg9o:CcX-4mgWvbU:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=KCI3R9bUg9o:CcX-4mgWvbU:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=KCI3R9bUg9o:CcX-4mgWvbU:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=KCI3R9bUg9o:CcX-4mgWvbU:YwkR-u9nhCs"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=YwkR-u9nhCs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=KCI3R9bUg9o:CcX-4mgWvbU:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=KCI3R9bUg9o:CcX-4mgWvbU:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=KCI3R9bUg9o:CcX-4mgWvbU:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=KCI3R9bUg9o:CcX-4mgWvbU:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=KCI3R9bUg9o:CcX-4mgWvbU:-BTjWOF_DHI" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/greentechspot/~4/KCI3R9bUg9o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.intechgrity.com/wp-category-post-list-version-2-released/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		<feedburner:origLink>http://www.intechgrity.com/wp-category-post-list-version-2-released/</feedburner:origLink></item>
		<item>
		<title>Get post count of a category including sub-categories in WordPress</title>
		<link>http://feedproxy.google.com/~r/greentechspot/~3/29Fvuo87ZoU/</link>
		<comments>http://www.intechgrity.com/get-post-count-of-a-category-including-sub-categories-in-wordpress/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 13:39:46 +0000</pubDate>
		<dc:creator>Swashata</dc:creator>
				<category><![CDATA[WP Programming]]></category>
		<category><![CDATA[wordpress api]]></category>
		<category><![CDATA[wordpress hacks]]></category>

		<guid isPermaLink="false">http://www.intechgrity.com/?p=974</guid>
		<description><![CDATA[<p><p>Original post published <a href="<a href="http://www.intechgrity.com/get-post-count-of-a-category-including-sub-categories-in-wordpress/">Get post count of a category including sub-categories in WordPress</a>">here</a></p><p>From the title, you probably have guessed what I am going to talk about. In WordPress, we have many APIs to list down the category, but when we use the get_category function, it lacks the ability to show the post counts from its sub or child categories. Whereas, when we use query_posts or get_posts to [...]</p></p><p>- By <a href="http://www.intechgrity.com">InTechgrity - Amalgamating Life &amp; Technology</a></p>
Related posts:<ol>
<li><a href='http://www.intechgrity.com/properly-add-pagination-to-your-wordpress-plugin/' rel='bookmark' title='Properly add pagination to your WordPress Plugin'>Properly add pagination to your WordPress Plugin</a></li>
<li><a href='http://www.intechgrity.com/add-archive-page-wordpress-blog-custom-page-template/' rel='bookmark' title='Howto: Add an Archive Page to your WordPress blog using Custom Page Template'>Howto: Add an Archive Page to your WordPress blog using Custom Page Template</a></li>
<li><a href='http://www.intechgrity.com/how-to-get-the-souce-url-of-the-featured-image-in-wordpress/' rel='bookmark' title='How to get the souce URL of the featured image in WordPress'>How to get the souce URL of the featured image in WordPress</a></li>
<li><a href='http://www.intechgrity.com/add-dynamic-login-logout-n-site-admin-button-to-wordpress-using-wp-api/' rel='bookmark' title='Add dynamic Login Logout n Site Admin button to WordPress using WP API'>Add dynamic Login Logout n Site Admin button to WordPress using WP API</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/oCndF4mLa2katyTKjAxfKIVBljo/0/da"><img src="http://feedads.g.doubleclick.net/~a/oCndF4mLa2katyTKjAxfKIVBljo/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/oCndF4mLa2katyTKjAxfKIVBljo/1/da"><img src="http://feedads.g.doubleclick.net/~a/oCndF4mLa2katyTKjAxfKIVBljo/1/di" border="0" ismap="true"></img></a></p><p>Original post published <a href="<a href="http://www.intechgrity.com/get-post-count-of-a-category-including-sub-categories-in-wordpress/">Get post count of a category including sub-categories in WordPress</a>">here</a></p><p><img class="aligncenter size-full wp-image-975" title="Get post count of a category with child" src="http://www.intechgrity.com/wp-content/uploads/2012/01/get-post-count-from-cat-with-child.png" alt="get-post-count-from-cat-with-child" width="500" height="300" />From the title, you probably have guessed what I am going to talk about. In WordPress, we have many APIs to list down the category, but when we use the get_category function, it lacks the ability to show the post counts from its sub or child categories. Whereas, when we use <span class="code">query_posts</span> or <span class="code">get_posts</span> to get posts from a particular category, it returns posts from child categories as well.</p>
<p>I faced this problem, while developing the 2nd version of the <a title="WP Category Post List Plugin – List your posts filtered by categories with thumbnails" href="http://www.intechgrity.com/wp-category-post-list-plugin-list-your-posts-filtered-by-categories-with-thumbnails/" target="_blank">WP-CPL</a> plugin. So I came up with a custom function which will return total post counts from the specified category and its child categories (if any).</p>
<p>Here are the codes and the usage instruction.</p>
<h2>The Custom Function:</h2>
<pre class="brush: php; title: ; notranslate">
function wp_get_cat_postcount($id) {
	$cat = get_category($id);
	$count = (int) $cat-&gt;count;
	$taxonomy = 'category';
	$args = array(
	  'child_of' =&gt; $id,
	);
	$tax_terms = get_terms($taxonomy,$args);
	foreach ($tax_terms as $tax_term) {
		$count +=$tax_term-&gt;count;
	}
	return $count;
}
</pre>
<h2>Usage Guide:</h2>
<p>The usage of this function is pretty straight forward. You call the function whenever you need passing the category id. Say, the category ID is 2. You call it with something like this:</p>
<pre class="brush: php; title: ; notranslate">
The total number of posts under &quot;My Awesome Category&quot; is &lt;?php echo wp_get_cat_postcount(2); ?&gt;
</pre>
<p>Well, that&#8217;s all. Short and informative. If you have any questions, be sure to drop in using comments.</p>
<p>Related posts:<ol>
<li><a href='http://www.intechgrity.com/properly-add-pagination-to-your-wordpress-plugin/' rel='bookmark' title='Properly add pagination to your WordPress Plugin'>Properly add pagination to your WordPress Plugin</a></li>
<li><a href='http://www.intechgrity.com/add-archive-page-wordpress-blog-custom-page-template/' rel='bookmark' title='Howto: Add an Archive Page to your WordPress blog using Custom Page Template'>Howto: Add an Archive Page to your WordPress blog using Custom Page Template</a></li>
<li><a href='http://www.intechgrity.com/how-to-get-the-souce-url-of-the-featured-image-in-wordpress/' rel='bookmark' title='How to get the souce URL of the featured image in WordPress'>How to get the souce URL of the featured image in WordPress</a></li>
<li><a href='http://www.intechgrity.com/add-dynamic-login-logout-n-site-admin-button-to-wordpress-using-wp-api/' rel='bookmark' title='Add dynamic Login Logout n Site Admin button to WordPress using WP API'>Add dynamic Login Logout n Site Admin button to WordPress using WP API</a></li>
</ol></p><p>- By <a href="http://www.intechgrity.com">InTechgrity - Amalgamating Life &amp; Technology</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/greentechspot?a=29Fvuo87ZoU:mSjQAEh3ZCE:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=29Fvuo87ZoU:mSjQAEh3ZCE:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=29Fvuo87ZoU:mSjQAEh3ZCE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=29Fvuo87ZoU:mSjQAEh3ZCE:nQ_hWtDbxek"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=nQ_hWtDbxek" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=29Fvuo87ZoU:mSjQAEh3ZCE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=29Fvuo87ZoU:mSjQAEh3ZCE:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=29Fvuo87ZoU:mSjQAEh3ZCE:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=29Fvuo87ZoU:mSjQAEh3ZCE:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=29Fvuo87ZoU:mSjQAEh3ZCE:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=29Fvuo87ZoU:mSjQAEh3ZCE:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=29Fvuo87ZoU:mSjQAEh3ZCE:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=29Fvuo87ZoU:mSjQAEh3ZCE:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=29Fvuo87ZoU:mSjQAEh3ZCE:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=29Fvuo87ZoU:mSjQAEh3ZCE:YwkR-u9nhCs"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=YwkR-u9nhCs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=29Fvuo87ZoU:mSjQAEh3ZCE:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=29Fvuo87ZoU:mSjQAEh3ZCE:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=29Fvuo87ZoU:mSjQAEh3ZCE:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=29Fvuo87ZoU:mSjQAEh3ZCE:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=29Fvuo87ZoU:mSjQAEh3ZCE:-BTjWOF_DHI" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/greentechspot/~4/29Fvuo87ZoU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.intechgrity.com/get-post-count-of-a-category-including-sub-categories-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.intechgrity.com/get-post-count-of-a-category-including-sub-categories-in-wordpress/</feedburner:origLink></item>
		<item>
		<title>MySQL: Working with date time arithmetic #Part 2.3.1</title>
		<link>http://feedproxy.google.com/~r/greentechspot/~3/6iiR30Apuo0/</link>
		<comments>http://www.intechgrity.com/mysql-working-with-date-time-arithmetic-part-2-3-1/#comments</comments>
		<pubDate>Mon, 19 Dec 2011 13:49:31 +0000</pubDate>
		<dc:creator>Swashata</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql-datetime]]></category>

		<guid isPermaLink="false">http://www.intechgrity.com/?p=942</guid>
		<description><![CDATA[<p><p>Original post published <a href="<a href="http://www.intechgrity.com/mysql-working-with-date-time-arithmetic-part-2-3-1/">MySQL: Working with date time arithmetic #Part 2.3.1</a>">here</a></p><p>So, this is the second last part of the long awaited MySQL datetime series. Previously we have leant how to work with MySQL datetime datatypes and how to automate some insertions using some MySQL datetime commands. Obviously the only thing left to discuss is, the (difficult) datetime arithmetic inside MySQL. As in any language, the [...]</p></p><p>- By <a href="http://www.intechgrity.com">InTechgrity - Amalgamating Life &amp; Technology</a></p>
Related posts:<ol>
<li><a href='http://www.intechgrity.com/automatically-insert-current-date-and/' rel='bookmark' title='Automatically insert Current Date and Time in MySQL table #Part – 2.2'>Automatically insert Current Date and Time in MySQL table #Part – 2.2</a></li>
<li><a href='http://www.intechgrity.com/mysql-date-and-time-datatypes-overview/' rel='bookmark' title='MySQL date and time DataTypes Overview: DATE, TIME, DATETIME, TIMESTAMP, YEAR &amp; Zero Values #Part2.1'>MySQL date and time DataTypes Overview: DATE, TIME, DATETIME, TIMESTAMP, YEAR &amp; Zero Values #Part2.1</a></li>
<li><a href='http://www.intechgrity.com/mysql-datatypes-working-with-fraction-and-decimal-dec/' rel='bookmark' title='MySQL datatypes: working with fraction and decimal [DEC]'>MySQL datatypes: working with fraction and decimal [DEC]</a></li>
<li><a href='http://www.intechgrity.com/mysql-data-types-char-varchar-int-text/' rel='bookmark' title='MySQL data types: CHAR, VARCHAR, INT, TEXT #Part-1'>MySQL data types: CHAR, VARCHAR, INT, TEXT #Part-1</a></li>
<li><a href='http://www.intechgrity.com/create-login-admin-logout-page-in-php-w/' rel='bookmark' title='Create Login Admin &amp; Logout Page in PHP w/ SESSION n MySQL'>Create Login Admin &amp; Logout Page in PHP w/ SESSION n MySQL</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/XbyRbZgnYRF5-2qX9m7zD93N0m8/0/da"><img src="http://feedads.g.doubleclick.net/~a/XbyRbZgnYRF5-2qX9m7zD93N0m8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/XbyRbZgnYRF5-2qX9m7zD93N0m8/1/da"><img src="http://feedads.g.doubleclick.net/~a/XbyRbZgnYRF5-2qX9m7zD93N0m8/1/di" border="0" ismap="true"></img></a></p><p>Original post published <a href="<a href="http://www.intechgrity.com/mysql-working-with-date-time-arithmetic-part-2-3-1/">MySQL: Working with date time arithmetic #Part 2.3.1</a>">here</a></p><p>So, this is the second last part of the long awaited MySQL datetime series. Previously we have leant how to work with MySQL datetime datatypes and how to automate some insertions using some MySQL datetime commands. Obviously the only thing left to discuss is, the (difficult) datetime arithmetic inside MySQL. As in any language, the datetime arithmetic is not as straight forward as normal arithmetic. The reason is simple, we can&#8217;t say 2+2=4 while dealing with dates <img src='http://www.intechgrity.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p style="text-align: center;"><img class="aligncenter" title="MySQL Datetime Arithmetic" src="http://www.intechgrity.com/wp-content/uploads/2011/12/mysql-datetime-arithmetic.png" alt="" width="500" height="300" /></p>
<p style="text-align: justify;">Suppose we have a date, &#8217;2004-02-28&#8242; in YYYY-MM-DD format (which is, a default datetime format for MySQL) and we want to add one more day to the date. So, the result is (supposedly) &#8217;2004-03-01&#8242;. But wait, 2004 is a leap year, so it should be &#8217;2004-02-29&#8242;, right?</p>
<p style="text-align: justify;">These are only a few of the difficulties we face while dealing with datetime arithmetic. Luckily, like any efficient programming language, MySQL (although it is a structured query language) has it&#8217;s own set of functions to deal with all these datetime stuffs. Now let us see how we can effectively use those functions to do all our datetime stuffs with queries. But before we start, I would recommend you to go through these two posts related to MySQL:</p>
<ol>
<li><a href="http://www.intechgrity.com/mysql-date-and-time-datatypes-overview/">MySQL date, time and datetime datatype overview</a></li>
<li><a href="http://www.intechgrity.com/automatically-insert-current-date-and/">Automatically insert date and time in MySQL tables</a></li>
</ol>
<p>Done? Okay, now let us move into further details. In this tutorial we will discuss only the basic and primary arithmetic. In 90% of the cases we will need only these concepts to get our jobs done. Please note that <em>we will show nesting only with default current datetime mysql functions</em>. <em><strong>The nesting is done basically depending on the format of the argument of the main function and format of the return of the nested function</strong></em>.</p>
<h2>#1: The basic date time arithmetic in MySQL</h2>
<p>To learn the basic arithmetic calculations, we need to learn three (basically two) date/time functions</p>
<ul>
<li>DATE_ADD</li>
<li>DATE_SUB</li>
<li>ADDTIME</li>
<li>SUBTIME</li>
</ul>
<h3>#1.1: DATE_ADD &#8211; adds INTERVALS to date:</h3>
<p><span class="spanlight">DATE_ADD</span>, as the name suggests, adds specified interval to the provided date. The syntax and usage is given below.</p>
<h4>Syntax:</h4>
<pre class="brush: sql; title: ; notranslate">DATE_ADD('YYYY-MM-DD HH:mm:SS', INTERVAL &lt;expr&gt; &lt;UNIT&gt;)</pre>
<p>So, it passes two arguments.</p>
<ul>
<li>The first argument is the <span class="code">YYYY-MM-DD HH:mm:SS</span> format. We can ignore the <span class="code">HH:mm:SS</span> and use only <span class="code">YYYY-MM-DD</span> in case we want only date related calculations.</li>
<li>The second argument passes the <span class="code">INTERVAL</span>which is to be added with the proper value. The expressions are
<ul>
<li>expr: The positive or negative integer which to be added to the mentioned date</li>
<li>UNIT: The unit of the expr. This can be day, month, hour, minute, second and so on. A detailed instruction is found on the table below.</li>
</ul>
</li>
</ul>
<table class="css3table">
<thead>
<tr>
<th scope="col"> UNIT</th>
<th scope="col">EXPR</th>
<th scope="col">Example</th>
</tr>
</thead>
<tbody>
<tr>
<td> <code>MICROSECOND</code></td>
<td>Microseconds<code></code></td>
<td> INTERVAL 100 MICROSECOND</td>
</tr>
<tr>
<td> <code>SECOND</code></td>
<td>Seconds</td>
<td> INTERVAL -5 SECOND</td>
</tr>
<tr>
<td> <code>MINUTE</code></td>
<td>Minutes</td>
<td> INTERVAL 30 MINUTE</td>
</tr>
<tr>
<td> <code>HOUR</code></td>
<td>Hours</td>
<td> INTERVAL 2 HOUR</td>
</tr>
<tr>
<td> <code>DAY</code></td>
<td>Days</td>
<td> INTERVAL 5 DAY</td>
</tr>
<tr>
<td> <code>WEEK</code></td>
<td>Weeks</td>
<td> INTERVAL 2 WEEK</td>
</tr>
<tr>
<td> <code>MONTH</code></td>
<td>Months</td>
<td> INTERVAL 4 MONTH</td>
</tr>
<tr>
<td> <code>YEAR</code></td>
<td>Years</td>
<td> INTERVAL 2 YEAR</td>
</tr>
</tbody>
</table>
<p>Those were only a few. More detailed list of Unit vs Expr can be found <a href="http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add" target="_blank">here</a>.</p>
<h4>Nesting:</h4>
<p>The above function can also be nested with proper <a title="Automatically insert Current Date and Time in MySQL table #Part – 2.2" href="http://www.intechgrity.com/automatically-insert-current-date-and/" target="_blank">MySQL datetime functions</a>. For example, <span class="spanlight">CURDATE()</span> or <span class="spanlight">NOW()</span> can be passed into the first argument.</p>
<h4>Examples:</h4>
<p>Here are some direct usage of DATE_ADD using SELECT query:</p>
<pre class="brush: sql; title: ; notranslate">SELECT DATE_ADD('2004-02-28', INTERVAL 1 DAY) AS leap_year;
SELECT DATE_ADD(CURDATE(), INTERVAL 1 YEAR) AS day_next_year;
SELECT YEAR(DATE_ADD(CURDATE(), INTERVAL 101 YEAR)) AS next_101_year; --Extracts the year from the date_add arithmetic
SELECT DATE_ADD(NOW(), INTERVAL 30 MINUTE) AS time_next_half_hour;</pre>
<p>The output is shown below</p>
<div id="attachment_947" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.intechgrity.com/wp-content/uploads/2011/12/mysql-date_add-examples1.png"><img class="size-medium wp-image-947" title="mysql-date_add-examples" src="http://www.intechgrity.com/wp-content/uploads/2011/12/mysql-date_add-examples1-300x204.png" alt="MySQL DATE_ADD Examples" width="300" height="204" /></a><p class="wp-caption-text">MySQL DATE_ADD Examples</p></div>
<h3>#1.2: DATE_SUB &#8211; subtracts INTERVAL from date:</h3>
<p>Theoretically, it does the same job as DATE_ADD with negative interval. So the following codes are similar</p>
<pre class="brush: sql; title: ; notranslate">--So the code
SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY);
--is equivalent to
SELECT DATE_ADD(CURDATE(), INTERVAL -1 DAY);</pre>
<p>It has the same synopsis (syntax) and expressions as <span class="spanlight">DATE_ADD</span>. The output of the above query is shown below.</p>
<div id="attachment_948" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.intechgrity.com/wp-content/uploads/2011/12/date_add-vs-date_sub-mysql.png"><img class="size-medium wp-image-948" title="DATE_ADD vs DATE_SUB in MySQL" src="http://www.intechgrity.com/wp-content/uploads/2011/12/date_add-vs-date_sub-mysql-300x156.png" alt="DATE_ADD vs DATE_SUB in MySQL" width="300" height="156" /></a><p class="wp-caption-text">DATE_ADD vs DATE_SUB in MySQL</p></div>
<h3> #1.3: ADDTIME() and SUBTIME() to work only with time:</h3>
<p>As the names suggest, ADDTIME() is used for adding time to a specified time and SUBTIME() is used for subtracting time from a specified time. Here are in depth details.</p>
<h4>Syntax:</h4>
<pre class="brush: sql; title: ADDTIME synopsis; notranslate">ADDTIME(&lt;expr1&gt;, &lt;expr2&gt;);</pre>
<pre class="brush: sql; title: SUBTIME synopsis; notranslate">SUBTIME(&lt;expr1&gt;, &lt;expr2&gt;);</pre>
<ul>
<li><strong><em>expr1, expr2 </em></strong>are both in <span class="code">HH:mm:SS</span> format.</li>
<li>ADDTIME adds expr2 to expr1 and returns the result.</li>
<li>SUBTIME subtracts expr2 from expr1 and returns the result.</li>
</ul>
<h4>Nesting:</h4>
<p>This can be nested with time returning functions such as <span class="spanlight">CURTIME()</span>.</p>
<h4>Examples:</h4>
<pre class="brush: sql; title: ; notranslate">SELECT ADDTIME('12:00:01', '00:30:59');
SELECT SUBTIME('12:59:03', '00:09:04');
SELECT ADDTIME(CURTIME(), '14:00:00');</pre>
<p>The output is shown below</p>
<div id="attachment_949" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.intechgrity.com/wp-content/uploads/2011/12/mysql-addtime-and-subtime.png"><img class="size-medium wp-image-949" title="MySQL ADDTIME and SUBTIME" src="http://www.intechgrity.com/wp-content/uploads/2011/12/mysql-addtime-and-subtime-300x156.png" alt="MySQL ADDTIME and SUBTIME" width="300" height="156" /></a><p class="wp-caption-text">MySQL ADDTIME and SUBTIME</p></div>
<h2> #2: Advance date-time arithmetic functions:</h2>
<p>Now that we are familiar with the basics, let us now see, some advanced functions which will become handy in real world projects. Here we are going to discuss the following functions</p>
<ul>
<li>DATEDIFF</li>
<li>TIMEDIFF</li>
<li>LASTDAY</li>
<li>EXTRACT</li>
<li>MAKEDATE</li>
<li>MAKETIME</li>
</ul>
<h3>#2.1: DATEDIFF &#8211; calculates days between two dates:</h3>
<p>The difference between <span class="spanlight">DATEDIFF</span> and <span class="spanlight">DATE_SUB</span> is that, <span class="spanlight">DATEDIFF</span> returns the number of days between two dates. It can be either positive or negative.</p>
<h4>Syntax:</h4>
<pre class="brush: sql; title: ; notranslate">DATEDIFF(&lt;expr1&gt;, &lt;expr2&gt;)</pre>
<ul>
<li><strong><em>expr1, expr2</em></strong> can be either <span class="code">YYYY-MM-DD HH:mm:SS</span> or <span class="code">YYYY-MM-DD</span>. Only <span class="code">YYYY-MM-DD</span> will be used for the calculation</li>
<li>It returns <strong><em>expr1 &#8211; expr2</em></strong> in number of <strong>days</strong>.</li>
</ul>
<h4>Nesting:</h4>
<p>Due to the format of the arguments it supports, <span class="spanlight">CURDATE()</span> and <span class="spanlight">NOW()</span> can be nested.</p>
<h4>Example:</h4>
<pre class="brush: sql; title: ; notranslate">SELECT DATEDIFF('2010-12-31', '2011-01-01');
SELECT DATEDIFF('2011-12-31', '2010-01-01');
SELECT DATEDIFF('2011-12-21', '2011-12-30');
SELECT DATEDIFF(DATE_ADD(CURDATE(), INTERVAL 1 MONTH), CURDATE());</pre>
<p>The output is</p>
<div id="attachment_950" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.intechgrity.com/wp-content/uploads/2011/12/mysql-datediff.png"><img class="size-medium wp-image-950" title="MySQL DATEDIFF" src="http://www.intechgrity.com/wp-content/uploads/2011/12/mysql-datediff-300x199.png" alt="MySQL DATEDIFF" width="300" height="199" /></a><p class="wp-caption-text">Working with MySQL DATEDIFF</p></div>
<h4 class="faq">Food for thought:</h4>
<p>Note how the last query can be used to get the number of days in the upcoming month. Now try and think how we can use similar query to get the number of days in upcoming year.</p>
<div class='et-learn-more clearfix'>
					<h3 class='heading-more'><span>Want to check the answer?</span></h3>
					<div class='learn-more-content'><pre class="brush: sql; title: ; notranslate">SELECT DATEDIFF(DATE_ADD(NOW(), INTERVAL 1 YEAR), NOW());</pre>
<p>CURDATE could also be used, instead of NOW</div>
				</div>
<h3>#2.2: TIMEDIFF &#8211; calculates HH:mm:SS b/w two times:</h3>
<p>This is pretty straight forward. It takes two arguments in time format, subtracts and returns the result.</p>
<h4>Syntax:</h4>
<pre class="brush: sql; title: ; notranslate">TIMEDIFF(&lt;expr1&gt;, &lt;expr2&gt;)</pre>
<ul>
<li><strong><em>expr1, expr2</em></strong> is of the format <span class="code">HH:mm:SS</span></li>
<li>It returns <strong><em>expr1 &#8211; expr2</em></strong> as time value in <span class="code">HH:mm:SS</span> format.</li>
</ul>
<h4>Nesting:</h4>
<p>It can be nested with <span class="spanlight">CURTIME()</span> function. We will see this in the examples.</p>
<h4>Examples:</h4>
<pre class="brush: sql; title: ; notranslate">SELECT TIMEDIFF('24:12:01', '12:12:00');
SELECT TIMEDIFF(CURTIME(), '00:30:00');</pre>
<p>The output is shown below.</p>
<div id="attachment_951" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.intechgrity.com/wp-content/uploads/2011/12/mysql-timediff.png"><img class="size-medium wp-image-951" title="Using MySQL TIMEDIFF" src="http://www.intechgrity.com/wp-content/uploads/2011/12/mysql-timediff-300x114.png" alt="Using MySQL TIMEDIFF" width="300" height="114" /></a><p class="wp-caption-text">Using MySQL TIMEDIFF</p></div>
<h3>#2.3: LAST_DAY &#8211; of specified month of date:</h3>
<p>This returns the last day date of the year-month-day passed in the argument.</p>
<h4>Syntax:</h4>
<pre class="brush: sql; title: ; notranslate">LAST_DAY(&lt;date&gt;)</pre>
<ul>
<li><strong><em>date</em></strong> is the <span class="code">YYYY-MM-DD</span> value passed.</li>
<li>It returns a <span class="code">YYYY-MM-DD</span> which corresponds to the last day of the month of the year.</li>
</ul>
<h4>Nesting:</h4>
<p>As obvious, it can be nested with <span class="spanlight">CURDATE()</span> function.</p>
<h4>Examples:</h4>
<pre class="brush: sql; title: ; notranslate">SELECT LAST_DAY('2012-02-01');
SELECT LAST_DAY(CURDATE());</pre>
<p>The output is</p>
<div id="attachment_952" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.intechgrity.com/wp-content/uploads/2011/12/mysql-last_day.png"><img class="size-medium wp-image-952" title="Using MySQL LAST_DAY" src="http://www.intechgrity.com/wp-content/uploads/2011/12/mysql-last_day-300x109.png" alt="Using MySQL LAST_DAY" width="300" height="109" /></a><p class="wp-caption-text">Using MySQL LAST_DAY</p></div>
<h3>#2.4: EXTRACT &#8211; what you need from date/time stamp:</h3>
<p>This allows extracting a specific part of the datetime from the passed argument.</p>
<h4>Syntax:</h4>
<pre class="brush: sql; title: ; notranslate">EXTRACT(&lt;unit&gt; FROM &lt;date&gt;)</pre>
<ul>
<li>The <em><strong>unit</strong></em> is same as <span class="spanlight">DATE_ADD()</span>.</li>
<li>The <strong><em>date </em></strong>can be
<ul>
<li>Complete <span class="code">YYYY-MM-DD HH:mm:SS</span></li>
<li>Just <em>date</em> format as <span class="code">YYYY-MM-DD</span></li>
<li>Just <em>time</em> format as <span class="code">HH:mm:SS</span></li>
</ul>
</li>
</ul>
<p>It returns just the expression for the specified unit.</p>
<h4>Nesting:</h4>
<p>Because of the flexibility, it can be nested with all the date time functions as <span class="spanlight">NOW()</span>, <span class="spanlight">CURDATE()</span>, <span class="spanlight">CURTIME()</span> etc.</p>
<h4>Examples:</h4>
<pre class="brush: sql; title: ; notranslate">SELECT EXTRACT(MONTH FROM '2011-02-28');
SELECT EXTRACT(DAY FROM LAST_DAY('2012-02-01')); --effective eh?
SELECT EXTRACT(DAY FROM DATE_ADD(CURDATE(), INTERVAL 20 DAY)); --even more complex
SELECT EXTRACT(HOUR FROM CURTIME()); --Works with HH:mm:SS too</pre>
<p>The outputs are</p>
<div id="attachment_953" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.intechgrity.com/wp-content/uploads/2011/12/using-mysql-extract.png"><img class="size-medium wp-image-953" title="Using MySQL EXTRACT" src="http://www.intechgrity.com/wp-content/uploads/2011/12/using-mysql-extract-300x199.png" alt="Using MySQL EXTRACT" width="300" height="199" /></a><p class="wp-caption-text">Using MySQL EXTRACT</p></div>
<h3>#2.5: MAKEDATE &#8211; from year and day:</h3>
<p>It constructs a date when the year and day of the year is given.</p>
<h4>Syntax:</h4>
<pre class="brush: sql; title: ; notranslate">MAKEDATE(&lt;year&gt;, &lt;day_of_year&gt;)</pre>
<ul>
<li>The <strong><em>year</em></strong> is the year of which the date is to be calculated.</li>
<li>The <strong><em>day_of_year</em></strong> is the count of the day from the beginning.</li>
<li>It returns a date in <span class="code">YYYY-MM-DD</span> format.</li>
</ul>
<h4>Nesting:</h4>
<p>Due to the format of the input arguments, it can not be nested directly with any MySQL current datetime functions.</p>
<h4>Examples:</h4>
<pre class="brush: sql; title: ; notranslate">SELECT MAKEDATE(2012, 365);
SELECT MAKEDATE(2010, DATEDIFF(CURDATE(), '2011-04-12'));
SELECT MAKEDATE(2000, DATEDIFF(CURDATE(), '2000-01-01'));
SELECT MAKEDATE(2000, DATEDIFF(DATE_ADD(CURDATE(), INTERVAL 1 DAY), '2000-01-01')) AS today;</pre>
<p>The output is</p>
<div id="attachment_954" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.intechgrity.com/wp-content/uploads/2011/12/mysql-makedate.png"><img class="size-medium wp-image-954" title="Using MySQL MAKEDATE" src="http://www.intechgrity.com/wp-content/uploads/2011/12/mysql-makedate-300x204.png" alt="Using MySQL MAKEDATE" width="300" height="204" /></a><p class="wp-caption-text">Using MySQL MAKEDATE</p></div>
<h4 class="faq">Food for thought:</h4>
<p>Note how the last query gives today&#8217;s date. Can you think further to give same date for the next year? As in, today&#8217;s date is 2011-12-19. Can you print 2012-12-19 in similar approach?</p>
<div class='et-learn-more clearfix'>
					<h3 class='heading-more'><span>Want to check the answer?</span></h3>
					<div class='learn-more-content'><pre class="brush: sql; title: ; notranslate">SELECT MAKEDATE(2001, DATEDIFF(DATE_ADD(CURDATE(), INTERVAL 1 DAY), '2000-01-01')) AS next_year_today;</pre>
<p>Easy right? We just took the difference from the same year and constructed from one more year (2001).</div>
				</div>
<h3>#2.6: MAKETIME &#8211; from HH, mm &amp; SS:</h3>
<p>This is very simple, yet useful function. It constructs a Time format from the given arguments.</p>
<h4>Syntax:</h4>
<pre class="brush: sql; title: ; notranslate">MAKETIME(&lt;hour&gt;, &lt;minute&gt;, &lt;second&gt;)</pre>
<ul>
<li>The <em><strong>hour, minute, second</strong></em>arguments can hold only the legal values
<ul>
<li>0-59 for <em><strong>minute, second</strong></em></li>
</ul>
</li>
</ul>
<p>It returns a nicely formatted <span class="code">HH:mm:SS</span> value from the arguments.</p>
<h4>Nesting:</h4>
<p>Due to it&#8217;s format, it can not be nested with current datetime mysql functions.</p>
<h4>Examples:</h4>
<pre class="brush: sql; title: ; notranslate">SELECT MAKETIME(12, 34, 11);
SELECT MAKETIME(12, EXTRACT(MINUTE FROM CURTIME()), 59);</pre>
<p>The outputs are</p>
<div id="attachment_956" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.intechgrity.com/wp-content/uploads/2011/12/mysql-maketime.png"><img class="size-medium wp-image-956" title="Using MySQL MAKETIME" src="http://www.intechgrity.com/wp-content/uploads/2011/12/mysql-maketime-300x114.png" alt="Using MySQL MAKETIME" width="300" height="114" /></a><p class="wp-caption-text">Using MySQL MAKETIME</p></div>
<p>So that was all. Hope it will help you understand better the concept of MySQL datetime arithmetic. <em>If you have any doubt, just throw in using the comments form</em>. In the next tutorial, we will see how to use these functions in real world using a MySQL table. You can also check the <a href="http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html" target="_blank">official MySQL documentation</a> for more available datetime functions. Oh, and here is a downloadable SQL file for your ease!</p>
<div class="demo-download lonely"><a class="download" title="MySQL datetime arithmetic functions Downloaded 73" href="http://www.intechgrity.com/downloads/12">Download Now</a></div>
<p>Related posts:<ol>
<li><a href='http://www.intechgrity.com/automatically-insert-current-date-and/' rel='bookmark' title='Automatically insert Current Date and Time in MySQL table #Part – 2.2'>Automatically insert Current Date and Time in MySQL table #Part – 2.2</a></li>
<li><a href='http://www.intechgrity.com/mysql-date-and-time-datatypes-overview/' rel='bookmark' title='MySQL date and time DataTypes Overview: DATE, TIME, DATETIME, TIMESTAMP, YEAR &amp; Zero Values #Part2.1'>MySQL date and time DataTypes Overview: DATE, TIME, DATETIME, TIMESTAMP, YEAR &amp; Zero Values #Part2.1</a></li>
<li><a href='http://www.intechgrity.com/mysql-datatypes-working-with-fraction-and-decimal-dec/' rel='bookmark' title='MySQL datatypes: working with fraction and decimal [DEC]'>MySQL datatypes: working with fraction and decimal [DEC]</a></li>
<li><a href='http://www.intechgrity.com/mysql-data-types-char-varchar-int-text/' rel='bookmark' title='MySQL data types: CHAR, VARCHAR, INT, TEXT #Part-1'>MySQL data types: CHAR, VARCHAR, INT, TEXT #Part-1</a></li>
<li><a href='http://www.intechgrity.com/create-login-admin-logout-page-in-php-w/' rel='bookmark' title='Create Login Admin &amp; Logout Page in PHP w/ SESSION n MySQL'>Create Login Admin &amp; Logout Page in PHP w/ SESSION n MySQL</a></li>
</ol></p><p>- By <a href="http://www.intechgrity.com">InTechgrity - Amalgamating Life &amp; Technology</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/greentechspot?a=6iiR30Apuo0:D6LMwtPwpC4:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=6iiR30Apuo0:D6LMwtPwpC4:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=6iiR30Apuo0:D6LMwtPwpC4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=6iiR30Apuo0:D6LMwtPwpC4:nQ_hWtDbxek"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=nQ_hWtDbxek" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=6iiR30Apuo0:D6LMwtPwpC4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=6iiR30Apuo0:D6LMwtPwpC4:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=6iiR30Apuo0:D6LMwtPwpC4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=6iiR30Apuo0:D6LMwtPwpC4:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=6iiR30Apuo0:D6LMwtPwpC4:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=6iiR30Apuo0:D6LMwtPwpC4:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=6iiR30Apuo0:D6LMwtPwpC4:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=6iiR30Apuo0:D6LMwtPwpC4:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=6iiR30Apuo0:D6LMwtPwpC4:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=6iiR30Apuo0:D6LMwtPwpC4:YwkR-u9nhCs"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=YwkR-u9nhCs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=6iiR30Apuo0:D6LMwtPwpC4:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=6iiR30Apuo0:D6LMwtPwpC4:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=6iiR30Apuo0:D6LMwtPwpC4:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=6iiR30Apuo0:D6LMwtPwpC4:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=6iiR30Apuo0:D6LMwtPwpC4:-BTjWOF_DHI" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/greentechspot/~4/6iiR30Apuo0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.intechgrity.com/mysql-working-with-date-time-arithmetic-part-2-3-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.intechgrity.com/mysql-working-with-date-time-arithmetic-part-2-3-1/</feedburner:origLink></item>
		<item>
		<title>C Program: Replacing a substring from a string</title>
		<link>http://feedproxy.google.com/~r/greentechspot/~3/tXVd7WLrhe0/</link>
		<comments>http://www.intechgrity.com/c-program-replacing-a-substring-from-a-string/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 05:31:06 +0000</pubDate>
		<dc:creator>Swashata</dc:creator>
				<category><![CDATA[C & C++ Sample Prorgams]]></category>
		<category><![CDATA[c program]]></category>
		<category><![CDATA[c-strcpy]]></category>
		<category><![CDATA[c-strlen]]></category>
		<category><![CDATA[c-strstr]]></category>

		<guid isPermaLink="false">http://www.intechgrity.com/?p=929</guid>
		<description><![CDATA[<p><p>Original post published <a href="<a href="http://www.intechgrity.com/c-program-replacing-a-substring-from-a-string/">C Program: Replacing a substring from a string</a>">here</a></p><p>This is a nice piece of program I wrote a few months ago. One of my students requested me to write this. So, here it is! Hope this might be useful for you&#8230; #1: What the program does: This program finds all the occurrences of a sub-string within a given string and replaces that with [...]</p></p><p>- By <a href="http://www.intechgrity.com">InTechgrity - Amalgamating Life &amp; Technology</a></p>
Related posts:<ol>
<li><a href='http://www.intechgrity.com/c-program-adding-two-polynomials-using-linked-list/' rel='bookmark' title='C Program: Adding two polynomials using Linked List'>C Program: Adding two polynomials using Linked List</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/B7ZVzO-xmPgQMYQ88zPlBlz_SxY/0/da"><img src="http://feedads.g.doubleclick.net/~a/B7ZVzO-xmPgQMYQ88zPlBlz_SxY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/B7ZVzO-xmPgQMYQ88zPlBlz_SxY/1/da"><img src="http://feedads.g.doubleclick.net/~a/B7ZVzO-xmPgQMYQ88zPlBlz_SxY/1/di" border="0" ismap="true"></img></a></p><p>Original post published <a href="<a href="http://www.intechgrity.com/c-program-replacing-a-substring-from-a-string/">C Program: Replacing a substring from a string</a>">here</a></p><p><a href="http://www.intechgrity.com/wp-content/uploads/2011/12/c-prog-new.png"><img class="aligncenter size-full wp-image-930" title="c-prog-new" src="http://www.intechgrity.com/wp-content/uploads/2011/12/c-prog-new.png" alt="" width="450" height="277" /></a>This is a nice piece of program I wrote a few months ago. One of my students requested me to write this. So, here it is! Hope this might be useful for you&#8230;</p>
<h2>#1: What the program does:</h2>
<p>This program finds all the occurrences of a sub-string within a given string and replaces that with our provided string. Basically there are many similar programs but, most of them lack the ability to find multiple occurrences. So I wrote this keeping in mind that the search string may appear many times in the original string. Here is the algo:</p>
<ul>
<li>Get the original, search and replace string from the user.</li>
<li>Write a user defined function to replace the first occurrence of the search string with the replace string.</li>
<li>Recursively call the function until there is no occurrence of the search string.</li>
</ul>
<p>Yes, there are many flaws in this program, like if the search string is a part of the replace string, the function will fail. I will try to remove these bugs when I get enough time. But this program will do the job for you in your college semesters <img src='http://www.intechgrity.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<h2>#2: Source Code:</h2>
<pre class="brush: cpp; title: String replace program in C; notranslate">
/**
 ****************************************************|
 * String replace Program                            |
 ****************************************************|
 * Takes three string input from the user
 * Replaces all the occurances of the second string
 * with the third string from the first string
 * @author Swashata
 */

/** Include Libraries */
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

/** Define the max char length */
#define MAX_L 4096

/** Prototypes */
void replace (char *, char *, char *);

int main(void) {
    char o_string[MAX_L], s_string[MAX_L], r_string[MAX_L]; //String storing variables

	printf(&quot;Please enter the original string (max length %d characters): &quot;, MAX_L);
	fflush(stdin);
	gets(o_string);

	printf(&quot;\nPlease enter the string to search (max length %d characters): &quot;, MAX_L);
	fflush(stdin);
	gets(s_string);

	printf(&quot;\nPlease enter the replace string (max length %d characters): &quot;, MAX_L);
	fflush(stdin);
	gets(r_string);

	printf(&quot;\n\nThe Original string\n*************************************\n&quot;);
	puts(o_string);

	replace(o_string, s_string, r_string);

	printf(&quot;\n\nThe replaced string\n*************************************\n&quot;);
	puts(o_string);

    return 0;
}

/**
 * The replace function
 *
 * Searches all of the occurrences using recursion
 * and replaces with the given string
 * @param char * o_string The original string
 * @param char * s_string The string to search for
 * @param char * r_string The replace string
 * @return void The o_string passed is modified
 */
void replace(char * o_string, char * s_string, char * r_string) {
      //a buffer variable to do all replace things
      char buffer[MAX_L];
      //to store the pointer returned from strstr
      char * ch;

      //first exit condition
      if(!(ch = strstr(o_string, s_string)))
              return;

      //copy all the content to buffer before the first occurrence of the search string
      strncpy(buffer, o_string, ch-o_string);

      //prepare the buffer for appending by adding a null to the end of it
      buffer[ch-o_string] = 0;

      //append using sprintf function
      sprintf(buffer+(ch - o_string), &quot;%s%s&quot;, r_string, ch + strlen(s_string));

      //empty o_string for copying
      o_string[0] = 0;
      strcpy(o_string, buffer);
      //pass recursively to replace other occurrences
      return replace(o_string, s_string, r_string);
 }
</pre>
<h2>#3: Output:</h2>
<div id="attachment_931" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.intechgrity.com/wp-content/uploads/2011/12/string-replace-c-output.png"><img class="size-medium wp-image-931" title="string-replace-c-output" src="http://www.intechgrity.com/wp-content/uploads/2011/12/string-replace-c-output-300x171.png" alt="" width="300" height="171" /></a><p class="wp-caption-text">String replace output</p></div>
<p>So that was it. If you have any better programming approach, then do share with us!</p>
<p>Related posts:<ol>
<li><a href='http://www.intechgrity.com/c-program-adding-two-polynomials-using-linked-list/' rel='bookmark' title='C Program: Adding two polynomials using Linked List'>C Program: Adding two polynomials using Linked List</a></li>
</ol></p><p>- By <a href="http://www.intechgrity.com">InTechgrity - Amalgamating Life &amp; Technology</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/greentechspot?a=tXVd7WLrhe0:c-LOFd1ayiw:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=tXVd7WLrhe0:c-LOFd1ayiw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=tXVd7WLrhe0:c-LOFd1ayiw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=tXVd7WLrhe0:c-LOFd1ayiw:nQ_hWtDbxek"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=nQ_hWtDbxek" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=tXVd7WLrhe0:c-LOFd1ayiw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=tXVd7WLrhe0:c-LOFd1ayiw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=tXVd7WLrhe0:c-LOFd1ayiw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=tXVd7WLrhe0:c-LOFd1ayiw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=tXVd7WLrhe0:c-LOFd1ayiw:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=tXVd7WLrhe0:c-LOFd1ayiw:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=tXVd7WLrhe0:c-LOFd1ayiw:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=tXVd7WLrhe0:c-LOFd1ayiw:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=tXVd7WLrhe0:c-LOFd1ayiw:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=tXVd7WLrhe0:c-LOFd1ayiw:YwkR-u9nhCs"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=YwkR-u9nhCs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=tXVd7WLrhe0:c-LOFd1ayiw:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=tXVd7WLrhe0:c-LOFd1ayiw:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=tXVd7WLrhe0:c-LOFd1ayiw:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=tXVd7WLrhe0:c-LOFd1ayiw:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=tXVd7WLrhe0:c-LOFd1ayiw:-BTjWOF_DHI" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/greentechspot/~4/tXVd7WLrhe0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.intechgrity.com/c-program-replacing-a-substring-from-a-string/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.intechgrity.com/c-program-replacing-a-substring-from-a-string/</feedburner:origLink></item>
		<item>
		<title>C Program: Adding two polynomials using Linked List</title>
		<link>http://feedproxy.google.com/~r/greentechspot/~3/FZEiZNFkIAs/</link>
		<comments>http://www.intechgrity.com/c-program-adding-two-polynomials-using-linked-list/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 06:26:13 +0000</pubDate>
		<dc:creator>Swashata</dc:creator>
				<category><![CDATA[C & C++ Sample Prorgams]]></category>
		<category><![CDATA[c program]]></category>
		<category><![CDATA[linked list]]></category>

		<guid isPermaLink="false">http://www.intechgrity.com/?p=915</guid>
		<description><![CDATA[<p><p>Original post published <a href="<a href="http://www.intechgrity.com/c-program-adding-two-polynomials-using-linked-list/">C Program: Adding two polynomials using Linked List</a>">here</a></p><p>So, this is our first C program in the blog. We first thought of creating a separate blog for C &#38; C++ related posts, but because of the maintenance issue, we finally decided to merge it to the main blog. So, without any further here is the program. #1: What the program does: This program [...]</p></p><p>- By <a href="http://www.intechgrity.com">InTechgrity - Amalgamating Life &amp; Technology</a></p>
Related posts:<ol>
<li><a href='http://www.intechgrity.com/c-program-replacing-a-substring-from-a-string/' rel='bookmark' title='C Program: Replacing a substring from a string'>C Program: Replacing a substring from a string</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[
<p><a href="http://feedads.g.doubleclick.net/~a/pzGxdBDfS1nfEInGSRzLoL__QlU/0/da"><img src="http://feedads.g.doubleclick.net/~a/pzGxdBDfS1nfEInGSRzLoL__QlU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/pzGxdBDfS1nfEInGSRzLoL__QlU/1/da"><img src="http://feedads.g.doubleclick.net/~a/pzGxdBDfS1nfEInGSRzLoL__QlU/1/di" border="0" ismap="true"></img></a></p><p>Original post published <a href="<a href="http://www.intechgrity.com/c-program-adding-two-polynomials-using-linked-list/">C Program: Adding two polynomials using Linked List</a>">here</a></p><p><a href="http://www.intechgrity.com/wp-content/uploads/2011/11/c-prog.png"><img class="aligncenter size-medium wp-image-919" title="c-prog" src="http://www.intechgrity.com/wp-content/uploads/2011/11/c-prog-300x182.png" alt="" width="300" height="182" /></a></p>
<p>So, this is our first C program in the blog. We first thought of creating a separate blog for C &amp; C++ related posts, but because of the maintenance issue, we finally decided to merge it to the main blog. So, without any further here is the program.</p>
<h2>#1: What the program does:</h2>
<p>This program is a practical implementation of the data structure &#8220;<strong>Linked List</strong>&#8220;. We use a linked list to dynamically store user input of polynomial expressions and then we add two polynomials using some simple arithmetic. For this, we follow the simple strategy:</p>
<ul>
<li>Make a polynomial abstract datatype using <em><strong>struct</strong></em> which basically implements a linked list.</li>
<li>We write different functions for Creating (ie, adding more nodes to the linked list) a polynomial function, Adding two polynomials and Showing a polynomial expression.</li>
<li>Finally we write the main function with menu driven ability to add as many pairs of polynomials the user wants.</li>
</ul>
<h2>#2: Source Code:</h2>
<pre class="brush: cpp; tab-size: 4; title: Adding two polynomials using Linked List; notranslate">
/**
 * Add two polynomials
 * Using Linked List
 * @author Swashata
 * @for Dearest Froggie
 */

#include&lt;stdio.h&gt;
#include&lt;stdlib.h&gt;

/**
 * The structure for the polynomial
 * This is a linked list with two variable
 * int coeff The Coefficient
 * int pow The power of x
 */
typedef struct link {
	int coeff;
	int pow;
	struct link * next;
} my_poly;

/** The prototypes */
void my_create_poly(my_poly **);
void my_show_poly(my_poly *);
void my_add_poly(my_poly **, my_poly *, my_poly *);

/**
 * The simple menu driven main function
 */
int main(void) {
	int ch;
	do {
		my_poly * poly1, * poly2, * poly3;

		printf(&quot;\nCreate 1st expression\n&quot;);
		my_create_poly(&amp;poly1);
		printf(&quot;\nStored the 1st expression&quot;);
		my_show_poly(poly1);

		printf(&quot;\nCreate 2nd expression\n&quot;);
		my_create_poly(&amp;poly2);
		printf(&quot;\nStored the 2nd expression&quot;);
		my_show_poly(poly2);

		my_add_poly(&amp;poly3, poly1, poly2);
		my_show_poly(poly3);

		printf(&quot;\nAdd two more expressions? (Y = 1/N = 0): &quot;);
		scanf(&quot;%d&quot;, &amp;ch);
	} while (ch);
	return 0;
}

/**
 * The create polynomial function
 * @param my_poly ** node The pointer to the head of the polynomial
 * We will modify the parameter and will store the base address
 * @return void
 */
void my_create_poly(my_poly ** node) {
	int flag; //A flag to control the menu
	int coeff, pow;
	my_poly * tmp_node; //To hold the temporary last address
	tmp_node = (my_poly *) malloc(sizeof(my_poly)); //create the first node
	*node = tmp_node; //Store the head address to the reference variable
	do {
		//Get the user data
		printf(&quot;\nEnter Coeff:&quot;);
		scanf(&quot;%d&quot;, &amp;coeff);
		tmp_node-&gt;coeff = coeff;
		printf(&quot;\nEnter Pow:&quot;);
		scanf(&quot;%d&quot;, &amp;pow);
		tmp_node-&gt;pow = pow;
		//Done storing user data

		//Now increase the Linked on user condition
		tmp_node-&gt;next = NULL;

		//Ask user for continuation
		printf(&quot;\nContinue adding more terms to the polynomial list?(Y = 1/N = 0): &quot;);
		scanf(&quot;%d&quot;, &amp;flag);
		//printf(&quot;\nFLAG: %c\n&quot;, flag);
		//Grow the linked list on condition
		if(flag) {
			tmp_node-&gt;next = (my_poly *) malloc(sizeof(my_poly)); //Grow the list
			tmp_node = tmp_node-&gt;next;
			tmp_node-&gt;next = NULL;
		}
	} while (flag);
}

/**
 * The show polynomial function
 * Prints the Polynomial in user readable format
 * @param my_poly * node The polynomial linked list
 * @return void
 */
void my_show_poly(my_poly * node) {
	printf(&quot;\nThe polynomial expression is:\n&quot;);
	while(node != NULL) {
		printf(&quot;%dx^%d&quot;, node-&gt;coeff, node-&gt;pow);
		node = node-&gt;next;
		if(node != NULL)
			printf(&quot; + &quot;);
	}
}

/**
 * The polynomial add function
 * Adds two polynomial to a given variable
 * @param my_poly ** result Stores the result
 * @param my_poly * poly1 The first polynomial expression
 * @param my_poly * poly2 The second polynomial expression
 * @return void
 */
void my_add_poly(my_poly ** result, my_poly * poly1, my_poly * poly2) {
	my_poly * tmp_node; //Temporary storage for the linked list
	tmp_node = (my_poly *) malloc(sizeof(my_poly));
	tmp_node-&gt;next = NULL;
	*result = tmp_node; //Copy the head address to the result linked list

	//Loop while both of the linked lists have value
	while(poly1 &amp;&amp; poly2) {
		if (poly1-&gt;pow &gt; poly2-&gt;pow) {
			tmp_node-&gt;pow = poly1-&gt;pow;
			tmp_node-&gt;coeff = poly1-&gt;coeff;
			poly1 = poly1-&gt;next;
		}
		else if (poly1-&gt;pow &lt; poly2-&gt;pow) {
			tmp_node-&gt;pow = poly2-&gt;pow;
			tmp_node-&gt;coeff = poly2-&gt;coeff;
			poly2 = poly2-&gt;next;
		}
		else {
			tmp_node-&gt;pow = poly1-&gt;pow;
			tmp_node-&gt;coeff = poly1-&gt;coeff + poly2-&gt;coeff;
			poly1 = poly1-&gt;next;
			poly2 = poly2-&gt;next;
		}

		//Grow the linked list on condition
		if(poly1 &amp;&amp; poly2) {
			tmp_node-&gt;next = (my_poly *) malloc(sizeof(my_poly));
			tmp_node = tmp_node-&gt;next;
			tmp_node-&gt;next = NULL;
		}
	}

	//Loop while either of the linked lists has value
	while(poly1 || poly2) {
		//We have to create the list at beginning
		//As the last while loop will not create any unnecessary node
		tmp_node-&gt;next = (my_poly *) malloc(sizeof(my_poly));
		tmp_node = tmp_node-&gt;next;
		tmp_node-&gt;next = NULL;

		if(poly1) {
			tmp_node-&gt;pow = poly1-&gt;pow;
			tmp_node-&gt;coeff = poly1-&gt;coeff;
			poly1 = poly1-&gt;next;
		}
		if(poly2) {
			tmp_node-&gt;pow = poly2-&gt;pow;
			tmp_node-&gt;coeff = poly2-&gt;coeff;
			poly2 = poly2-&gt;next;
		}
	}

	printf(&quot;\nAddition Complete&quot;);
}
</pre>
<h2>#3: Output:</h2>
<div id="attachment_921" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.intechgrity.com/wp-content/uploads/2011/11/entering-the-first-expression.png"><img class="size-medium wp-image-921" title="entering-the-first-expression" src="http://www.intechgrity.com/wp-content/uploads/2011/11/entering-the-first-expression-300x191.png" alt="" width="300" height="191" /></a><p class="wp-caption-text">Entering the first expression</p></div>
<div id="attachment_920" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.intechgrity.com/wp-content/uploads/2011/11/entering-second-expression-showing-result.png"><img class="size-medium wp-image-920" title="entering-second-expression-showing-result" src="http://www.intechgrity.com/wp-content/uploads/2011/11/entering-second-expression-showing-result-300x192.png" alt="" width="300" height="192" /></a><p class="wp-caption-text">Entering second expression and showing result</p></div>
<p>So, that was all. If you think there is a better way, or have followed any other algorithm, don&#8217;t forget to drop them using comments.</p>
<p>Related posts:<ol>
<li><a href='http://www.intechgrity.com/c-program-replacing-a-substring-from-a-string/' rel='bookmark' title='C Program: Replacing a substring from a string'>C Program: Replacing a substring from a string</a></li>
</ol></p><p>- By <a href="http://www.intechgrity.com">InTechgrity - Amalgamating Life &amp; Technology</a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/greentechspot?a=FZEiZNFkIAs:GIQ2RYd0z00:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=FZEiZNFkIAs:GIQ2RYd0z00:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=FZEiZNFkIAs:GIQ2RYd0z00:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=FZEiZNFkIAs:GIQ2RYd0z00:nQ_hWtDbxek"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=nQ_hWtDbxek" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=FZEiZNFkIAs:GIQ2RYd0z00:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=FZEiZNFkIAs:GIQ2RYd0z00:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=FZEiZNFkIAs:GIQ2RYd0z00:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=FZEiZNFkIAs:GIQ2RYd0z00:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=FZEiZNFkIAs:GIQ2RYd0z00:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=FZEiZNFkIAs:GIQ2RYd0z00:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=TzevzKxY174" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=FZEiZNFkIAs:GIQ2RYd0z00:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=FZEiZNFkIAs:GIQ2RYd0z00:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=FZEiZNFkIAs:GIQ2RYd0z00:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=FZEiZNFkIAs:GIQ2RYd0z00:YwkR-u9nhCs"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=YwkR-u9nhCs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=FZEiZNFkIAs:GIQ2RYd0z00:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/greentechspot?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=FZEiZNFkIAs:GIQ2RYd0z00:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=FZEiZNFkIAs:GIQ2RYd0z00:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/greentechspot?a=FZEiZNFkIAs:GIQ2RYd0z00:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/greentechspot?i=FZEiZNFkIAs:GIQ2RYd0z00:-BTjWOF_DHI" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/greentechspot/~4/FZEiZNFkIAs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.intechgrity.com/c-program-adding-two-polynomials-using-linked-list/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.intechgrity.com/c-program-adding-two-polynomials-using-linked-list/</feedburner:origLink></item>
	</channel>
</rss>

