Pedigree/Family Tree using HTML table

For my recent project, i wanted to create a family tree structure for parent-child relationships. After a lot searches, i decided to build it using HTML table.

Lets begin…

First of all, we are going to write a render function which has an array of data to be shown.

$arrPedigree = array(
'name' => 'Parent',
'children' => array(
'name' => 'Child 1',
'children' => array(
'name' => 'Sub Child 11',
'children' => array(
'name' => 'Sub Sub Child 111',
'name' => 'Sub Sub Child 112',
'name' => 'Sub Child 12'
'name' => 'Child 2',
'children' => array(
'name' => 'Sub Child 21'
'name' => 'Sub Child 22'
view raw pedigree.php hosted with ❤ by GitHub

Finally we need to loop through the array to create the structure and we’ll use some CSS classes to draw some lines for connecting parent to its children.

Pedigree/Family Tree
Pedigree/Family Tree

Download Code Here


The conventions to be followed for OOP in PHP

Hi guys,

I always give preference to the conventions over configurations. If somebody wants to be a professional programmer then must follow the conventions.

Here are some conventions i came up with based on PEAR Coding Standards which are good.

1. ClassName – Emailer, Logger, ErrorHandler, PEAR(this is a package name, that is why, it is in CAPS)

2. Public Methods – log, logError, PEAR_init (to avoid method name collisions between packages)

3. Protected Methods – _log, _logError, _PEAR_initMe

4. Private Methods – __log, __logError, __PEAR_initMe

5. Constant/Static Variables – MY_FIRST_CONSTANT, PEAR_MY_FIRST_CONSTANT(to var name collisions between packages)

6. Global Variables – $_MY_FIRST_GLOBAL, $_PEAR_MY_FIRST_GLOBAL(to avoid var name collisions between packages)

I hope this will help to improve us. And this way, we can remember conventions easily, that is why i did not give the full description.

Url Rewriting using php, smarty and mod_rewrite

Let’s learn to rewrite the website url today.

According to me, before learning something new, we should take a look at why we need to do it and what’s the use of it.

Use of URL rewriting:
1. Making website URLs more user and search engine friendly.
2. Preventing undesired “inline linking”.
3. Not exposing the inner workings of a web site’s address to visitors

So let’s begin…

Project Name: url_rewriting
Dir. Structure: url_rewriting
– cache
– configs
– libs
– templates
– templates_c
– .htaccess
– other php files

What we want to achieve:
here we want to convert the following url

How we can achieve:
we need to first create a file “function.seo_optimise.php” in “smarty/lib/plugins/”, so that smarty will treat it as its own function without any hassal.

function smarty_function_seo_optimise($params, &$smarty)
// we will add code here later...

Done… 50%

Now secondly, we have to create a .htaccess file in the directory structure as shown above. And add following…

php_value error_reporting 7
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)/([0-9]+)/(.*)/UniversalSearch.html$ UniversalSearch.php?origin=$1&exp=$2&q=$3

Please note that, (.*) suggest the type of text we are sending to perticular querystring. Like for origin querystring, we are going to send anything including characters & numbers, or in case of exp querystring, we are going to send only numbers thats why we have used ([0-9]+) in order to restrict the querystring value to the numbers only.

Done... 70%

I know, you are confused now, because you are thinking that how smarty will know, (.*) for origin, ([0-9]+) for exp and (.*) for q. Do not worry, thats we have created "function.seo_optimise.php" file above. Now, open this file, and write the following code... please note that here we are going to send three querystrings to the page thats why we have to pass three parameters to the function also. These are the three parameters..

function smarty_function_seo_optimise($params, &$smarty)
    /* This is for three querystrings */
        $origin =  $params[origin];
        $exp     =  $params[exp];
        $q         =  $params[q];
   /* This is to recognise the page to which we are going to rewrite */
   if($params[type] == 'universal_page')
       if($params[urls] == 'Enable')
           return $origin."/".$exp."/".$q."/UniversalSearch.html";
           return "UniversalSearch.php?origin=".$origin."&exp=".$exp."&q=".$q

Done... 80%

Now let me explain you, this smarty function will transform our old url to new like this... Ok then, time to spell the beans... to convert that url we have to write following in .tpl file.

{seo_optimise urls=$seo_urls origin=box exp=1 q=php type=universal_page}

<a href="$seo_urls%20origin=box%20exp=1%20q=php%20type=universal_page%7D">
Click me

here is a explaination...

$seo_urls => Enable/Disable

when the page get loaded, that seo_optimise will pass the supplied parameters to the function of a same name created in smarty/lib/plugins/function.seo_optimise.php.

1. First, it will add the passed value to appropriete variables as mentioned above in this php file.
2. secondly, it will check which page you want to rewrite using "type" variable.
3. If it is "universal_page" and $seo_urls is "Enable" then it will return the url like or if $seo_urls is "Disable" then it will return the url like
Done... 100%

Using this way we can rewrite any url in any ways you want, just do not forget to enter the old url & new url in .htaccess file.