Tuesday, November 19, 2013

Ancestor, Descendant, Parent And Child Hierarchy Explained

Parent and child
The relationships between the various values are referred to as though they were part of a family tree. Each dimension value in a hierarchy (except the top-most value) has a parentvalue, which is the value directly above it in the structure. The dimension values directly below a parent are called its children.


Descendant and ancestor values
Each child value can also have children of its own, and so on. Multiple levels of dimension values that roll up to a common value are called descendants of that value, and the value itself is known as the ancestor of the descendent values.


This info will help during multiple level category management. I read this definitions while making multi level category manager in PHP for one project and helped me a lot. Before you make multi level category manager, you need to know what is parent, child, ancestor and descendant.

Ref: http://docs.oracle.com/html/A96138_01/u_05ch.html#1005283

Friday, November 15, 2013

How To Use JSONP With Demo?

As you may be aware you cannot directly load data files from another domain. This is a security issue that has been around for a long time and is commonly solved by sharing data through an API, REST or such. However there are ways around this and in this post we will look at the different options available to you such as a PHP Proxy Pass but in this post we will focus on JSONP.

JSONP stands for “JSON with Padding” and it is a workaround for loading data from different domains. It loads the script into the head of the DOM and thus you can access the information as if it were loaded on your own domain, thus by-passing the cross domain issue.

I've setup up one javascript file that contains some jsonp data.

nice.js.php
callback({date:"18:12:36"});
Additionally I've setup up two different HTML pages. Common for all of them, is that they will load one of the two javascripts and try to replace the contents of a span tag with the data in the date property of the json object.
The pages are:
1. scriptonly_nice.html - Loads nice.js.php by adding a script tag using normal javascript and DOM manipulation
2. jquery_nice.html - Loads nice.js.php by using jQuery's $.get(..., "jsonp")
Ref: http://erlend.oftedal.no/blog/?blogid=97
http://www.jquery4u.com/json/jsonp-examples/

Monday, November 11, 2013

How To Check If 24 Hours Have Passed in PHP?

You have in php strtotime() function to convert human readable dates to timestamps. Using strtotime function you can easily compare dates or timestamp with php.

In the following example, I have converted the two dates into timestamp using strtotime function and stored in separate variables. You can do many things for instance, compare two dates to find out which date is greater or lower. I have to find out if the date have been more than 24 hours, so I did following method, if 24 hours have passed.

// your first date coming from a mysql database (date fields) 
$dateA = '2013-11-11 23:10:30'; 
// your second date coming from a mysql database (date fields) 
$dateB = '2013-11-11 16:27:21'; 

$timediff = strtotime($dateA) - strtotime($dateB);

if($timediff > 86400){ 
    echo 'more than 24 hours';
}
else
{
 echo 'less than 24 hours';
}

If it exists other ways to achieve it, please share it. :)

Friday, November 8, 2013

How To Create Prefect Email Newsletter?

In my experience the key is to focus on three things. First, you should keep it simple. The more complex your email design, the more likely is it to choke on one of the popular clients with poor standards support. Second, you need to take your coding skills back a good decade. That often means nesting tables, bringing CSS inline and following the coding guidelines I’ll outline below. Finally, you need to test your designs regularly. Just because a template looks nice in Hotmail now, doesn’t mean it will look nice in all email client.
I always use following guidelines as a foundation.
Top 10 tips to design pixel perfect email newsletter.
1. Use tables for layout
2. Set the width in each cell, NOT THE TABLE

<table cellspacing="0" cellpadding="10" border="0">
	<tr>
		<td width="80"></td>
		<td width="280"></td>
	</tr>
</table>
3. Use nested TABLE
Table nesting is far more reliable than setting left and right margins or padding for table cells. If you can achieve the same effect by table nesting, that will always give you the best result across the buggier email clients.
4. Use a container TABLE for BODY background colors and background images
Many email clients ignore background colors specified in your CSS or the tag. To work around this, wrap your entire email with a 100% width table and give that a background color.
<table cellspacing="0" cellpadding="0" border="0" width="100%">
	<tr>
		<td bgcolor=”#000000”>
			Your email code goes here.
		</td>
	</tr>
</table>
5. Always use CSS INLINE
6. Avoid shorthand for fonts and hex notation
7. Avoid Paragraphs, use <br/> tags
8. Always include the dimensions of your image
9. Avoid PNGS
10. Don’t forget alt text

Ref: http://24ways.org/2009/rock-solid-html-emails/

Wednesday, November 6, 2013

How to Get The Last Character of a String Using jQuery?

You can use the .slice() method, its cross browser compatible.
var id = "example1";
id.slice(-1); //Outputs: 1
Getting the last character is easy, as you can treat strings as an array:
var id = "example2";
var lastChar = id[id.length-1]; //Outputs: 2
To get a section of a string, you can use the substr function
var id = "example3";
id.substr(id.length-1); //Outputs: 3