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

<channel>
	<title>The Tech Space &#187; function</title>
	<atom:link href="http://www.thetechspace.com/tag/function/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thetechspace.com</link>
	<description>php, jquery, flash and resources</description>
	<lastBuildDate>Tue, 08 Nov 2011 08:47:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Get Unlimited Parent and Child in PHP</title>
		<link>http://www.thetechspace.com/2010/05/21/get-unlimited-parent-and-child-in-php/</link>
		<comments>http://www.thetechspace.com/2010/05/21/get-unlimited-parent-and-child-in-php/#comments</comments>
		<pubDate>Fri, 21 May 2010 08:12:39 +0000</pubDate>
		<dc:creator>Thurein</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[recursion]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://www.thetechspace.com/?p=321</guid>
		<description><![CDATA[Well, let me ask you first. Have you already known about recursion? If not, recursion mean reuse function in this function. How is it ? For eg Like function one_function ($var){ one_function(332); } OK , So , how to related with this post title ? I would like to say absolutely related with recursion. Let&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Well, let me ask you first. Have you already known about recursion? If not, recursion mean reuse function in this function.</p>
<p>How is it ? For eg Like</p>
<pre class="brush:php">function one_function ($var){
           one_function(332);
}
</pre>
<p>OK , So , how to related with this post title ? I would like to say absolutely related with recursion. Let&#8217;s say, we would like to create category with parent and child.so, we have one table in database, category table. Table Structure Like:</p>

<table id="wp-table-reloaded-id-1-no-1" class="wp-table-reloaded wp-table-reloaded-id-1">
<thead>
	<tr class="row-1 odd">
		<th class="column-1">id</th><th class="column-2">name</th><th class="column-3">p_id</th>
	</tr>
</thead>
<tbody>
	<tr class="row-2 even">
		<td class="column-1">1</td><td class="column-2">Main Parent</td><td class="column-3">0</td>
	</tr>
	<tr class="row-3 odd">
		<td class="column-1">2</td><td class="column-2">Sub Parent</td><td class="column-3">1</td>
	</tr>
	<tr class="row-4 even">
		<td class="column-1">3</td><td class="column-2">Child</td><td class="column-3">2</td>
	</tr>
	<tr class="row-5 odd">
		<td class="column-1">4</td><td class="column-2">Parent 2</td><td class="column-3">0</td>
	</tr>
	<tr class="row-6 even">
		<td class="column-1">5</td><td class="column-2">Child 2</td><td class="column-3">4</td>
	</tr>
	<tr class="row-7 odd">
		<td class="column-1">6</td><td class="column-2">Child 3</td><td class="column-3">4</td>
	</tr>
	<tr class="row-8 even">
		<td class="column-1">7</td><td class="column-2">Child 4</td><td class="column-3">5</td>
	</tr>
</tbody>
</table>

<p><span id="more-321"></span>So, now I have created one table. I would like to get the out put like:</p>
<p>Main Parrent<br />
- Sub Parent<br />
&#8211; Child of sub parent<br />
Parent 2<br />
-  Child 2<br />
&#8211; Child of child 2<br />
- Child 3</p>
<p>So, how will you do it? How could we get it?</p>
<p>If you write the codes like, for eg :</p>
<pre class="brush:php">   $result = mysql_query ();
   while ( $row = mysql_fetch_assoc($result) ){

      echo $row[name];

      $result = mysql_query ();
      while ( $row = mysql_fetch_assoc($result) ){

            echo '- '.$row[name];
      }

   }
</pre>
<p>It would be work. But. If you have 3 or 4 or 5 levels and so on, you will got the trouble. So, what is the better way for that table? Shell we use recursion ?</p>
<p>I have written some code snippets like :</p>
<pre class="brush:php">
function display_child($parent, $level)
{
	$sql = "SELECT * from `category` WHERE p_id='$parent'";
	$result = mysql_query($sql);
	while ($row = mysql_fetch_array($result))
	{
		echo str_repeat('-',$level)." ".$row['name']."&lt;br /&gt;";
		display_child($row['id'], $level+1);
	}
}
</pre>
<p>Usage &#8211; display_child( parent_id, level )</p>
<pre class="brush:php">     display_children(0,0);
</pre>
<p>I hope it would be useful for some of your projects. Enjoy !!!!</p>
<h3><a href="http://www.thetechspace.com/?download=php_recursion" target="_blank">Download Source</a> ( size 1.1 kB)</h3>
<div class="shr-publisher-321"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thetechspace.com/2010/05/21/get-unlimited-parent-and-child-in-php/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>How to return more than one value or multi value in PHP</title>
		<link>http://www.thetechspace.com/2010/03/28/how-to-return-more-than-one-value-or-multi-value-in-php/</link>
		<comments>http://www.thetechspace.com/2010/03/28/how-to-return-more-than-one-value-or-multi-value-in-php/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 01:13:45 +0000</pubDate>
		<dc:creator>Thurein</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://www.thetechspace.com/?p=297</guid>
		<description><![CDATA[Some of PHP beginners (my friends) always ask me how to return two or more values from function. So , I thought, I may need to write the beginner tip at The Tech Space Blog. If your the advanced PHP programmer, you will say. So easy, It&#8217;s a piece of cake. For beginner, it would [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Some of PHP beginners (my friends) always ask me how to return two or more values from function. So , I thought, I may need to write the beginner tip at The Tech Space Blog. If your the advanced PHP programmer, you will say. So easy, It&#8217;s a piece of cake. For beginner, it would be a little difficult. So, let&#8217;s see how to write it.</p>
<p>For normal function ..</p>
<pre class="brush:php">
&lt;?

function calc ( $a, $b)
{

$sum = $a+$b;
return $sum;

}

echo $calc(2,3);

?&gt;
</pre>
<p>So, If you would like to return two or more value from that function, just only return as an array. Let&#8217;s see.</p>
<pre class="brush:php">
&lt;?php

function calc($a,$b){

$sum = $a+$b;
$multiply = $a * $b;
$divided = $a/$b;
$modulus = $a%$b;

return array( 'sum'=&gt;$sum, 'multiply'=&gt;$multiply, 'divided'=&gt; $divided, 'modulus'=&gt;$modulus );

}

$data = calc(3,4);

echo 'Sum value: '.$data['sum'].'&lt;br /&gt;';
echo 'Multiply value: '.$data['multiply'].'&lt;br /&gt;';
echo 'Divided value: '.$data['divided'].'&lt;br /&gt;';
echo 'Modulus value: '.$data['modulus'].'&lt;br /&gt;';

?&gt;
</pre>
<p>Enjoy !!!</p>
<div class="shr-publisher-297"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.thetechspace.com/2010/03/28/how-to-return-more-than-one-value-or-multi-value-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

