How add Integer in Datetime with help of MySql

Now I am describing how to add a specific datetime unit in date. TIMESTAMPADD function of mysql is very important when we are working on datetime part in mysql query.This function takes integer INTERVAL argument and return result datetime with given unit interval.
The unit and interval both are must be same unit type().which should be one of the following values: MICROSECOND(microseconds), SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR.

The Syntax is:

TIMESTAMPADD(unit,interval,datetime_expr)

Unit: Its unit type of interval, which you want add.
Interval : the integer value of ‘unit’ type
Exp: target datetime value

Example:

SELECT TIMESTAMPADD(WEEK,1,Now())
Result: 2012-05-21 17:27:25

TIMEDIFF() function in MySql

TIMEDIFF is another useful function in mysql to get datetime difference, Where this function returns time difference of both value like exp1- exp2.

The syntax of TIMEDIFF is:

TIMEDIFF(expr1,expr2)

Exp1: from date of datetime type
Exp2: to date of datetime type

Note: both value must be same datetime type. The result returned by TIMEDIFF() is limited to the range allowed for TIME values. Alternatively, you can use either of the functions TIMESTAMPDIFF() and UNIX_TIMESTAMP(), both of which return integers.

Example:

SELECT TIMEDIFF(’2011-12-31 23:59:59.000001′, ’2011-12-30 01:01:01.000002′)
Result: 46:58:57.999999

DateTime Difference in MYSQL

Now we are discussing how to get time difference in mysql.
There are a lot of mysql function for datetime calculation, one of them are TIMESTAMPDIFF.

Syntax is:

TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2)

Here one expression may be date type but other must be datatime type,the date type expression treated as date time with ’00:00:00’.

Where terms are following:

Unit: is return unit from result.
Exp1: from date
Exp2: to date

Example:

SELECT TIMESTAMPDIFF(MONTH,’2012-02-11′,’2012-07-01′)
Result: 4;
SELECT TIMESTAMPDIFF(MONTH,’2012-07-11′,’2012-01-01′)
Result: -6
SELECT TIMESTAMPDIFF(MINUTE,’2012-01-11′,’2012-05-01′)
Result: 159840

How to find all element of any div in Jquery

Hi,
below code is used for get all element listing with label and textbox.
for example if a div has image and when the user click the image then user will be able to edit the property of image in edit dialog box.

  1. <link href=“http://twitter.github.com/bootstrap/assets/css/bootstrap.css” rel=“stylesheet”>  
  2.     <link href=“http://twitter.github.com/bootstrap/assets/css/bootstrap-responsive.css” rel=“stylesheet”>  
  3.     <link href=“http://twitter.github.com/bootstrap/assets/css/docs.css” rel=“stylesheet”>  
  4.     <link href=“http://twitter.github.com/bootstrap/assets/js/google-code-prettify/prettify.css” rel=“stylesheet”>  
  5.   
  6.   
  7. <script type=“text/javascript” src=“http://platform.twitter.com/widgets.js”></script>  
  8. <script src=“http://twitter.github.com/bootstrap/assets/js/jquery.js”></script>  
  9.  <script src=“http://twitter.github.com/bootstrap/assets/js/google-code-prettify/prettify.js”></script>  
  10.     <script src=“http://twitter.github.com/bootstrap/assets/js/bootstrap-transition.js”></script>  
  11.     <script src=“http://twitter.github.com/bootstrap/assets/js/bootstrap-alert.js”></script>  
  12.     <script src=“http://twitter.github.com/bootstrap/assets/js/bootstrap-modal.js”></script>  
  13.     <script src=“http://twitter.github.com/bootstrap/assets/js/bootstrap-dropdown.js”></script>  
  14.     <script src=“http://twitter.github.com/bootstrap/assets/js/bootstrap-scrollspy.js”></script>  
  15.     <script src=“http://twitter.github.com/bootstrap/assets/js/bootstrap-tab.js”></script>  
  16.     <script src=“http://twitter.github.com/bootstrap/assets/js/bootstrap-tooltip.js”></script>  
  17.     <script src=“http://twitter.github.com/bootstrap/assets/js/bootstrap-popover.js”></script>  
  18.     <script src=“http://twitter.github.com/bootstrap/assets/js/bootstrap-button.js”></script>  
  19.     <script src=“http://twitter.github.com/bootstrap/assets/js/bootstrap-collapse.js”></script>  
  20.     <script src=“http://twitter.github.com/bootstrap/assets/js/bootstrap-carousel.js”></script>  
  21.     <script src=“http://twitter.github.com/bootstrap/assets/js/bootstrap-typeahead.js”></script>  
  22.     <script src=“http://twitter.github.com/bootstrap/assets/js/application.js”></script>  
  23.    
  24. <div class=“clearfix content-preview”>  
  25.          <div id=“view-content” class=“input”><div class=“marketing1″>  
  26.     <a title=“”>  
  27.         <img src=“http://www.google.com/images/flower-pictures-blue.jpg”>  
  28.     </a>  
  29. </div>  
  30. <div class=“marketing2″>  
  31.     <a title=“Adventure Designed Boots” href=“”>  
  32.         <img title=“Adventure Designed Boots.” alt=“Adventure Designed Boots” src=“http://www.google.com/a.jpg”>  
  33.     </a>  
  34. </div>  
  35. </div>  
  36.     </div>  
  37. <div class=“modal” id=“preview-static-block”>  
  38.     <div class=“modal-header”>  
  39.     <button class=“close” data-dismiss=“modal”>×</button>  
  40.   </div>  
  41. </div>  
  42. <script>  
  43.    
  44.  $(‘.input div’).hover(  
  45.                 function() {  
  46.                     var that = $(this);  
  47.                     $(this).css({  
  48.                         “position”:“relative”  
  49.                     });  
  50.                     var imageObj = $(this).find(“img”);  
  51.                     $(this).append(  
  52.                         $(“<span style=’top: ” +  $(this).height()/2 + “px; left:” + (imageObj.width() - 10 ) + “px; color:red; position:absolute; z-index:1111′ id=’imgEdit’  class=’btn’><a>Edit</a></span>”)  
  53.                         .bind(‘click’function(){  
  54.                             var nodes={};  
  55.                             $(this).parent().find(‘*’).not($(this)).each(function(i, el){  
  56.                                 for (var attr, i=0, attrs=el.attributes, l=attrs.length; i<l; i++){  
  57.                                     attr = attrs.item(i)  
  58.                                     nodes[attr.nodeName] = attr.nodeValue;  
  59.                                 }  
  60.                             });  
  61.                             var html = ‘<div class=”static-block-preview-header”><form>’;  
  62.                             $.each(nodes, function(key, value) {  
  63.                                 html += ‘<div class=”clearfix”>’;  
  64.                                 html += ‘<label> ’ + key + ‘ </label>’ + ‘<div class=”input”><input type=”text” value=”‘ + value + ‘” /> </div>’;  
  65.                                 html += ‘</div>’;  
  66.                             });  
  67.                             html += ‘</form></div>’;  
  68.                             $(‘#preview-static-block’).html(html);  
  69.                             previewStaticBlock.show();  
  70.   
  71.                         })  
  72.                         );  
  73.                 },  
  74.                 function(){  
  75.                     $(this).find(“span:last”).remove();  
  76.                 });  
  77.                 previewStaticBlock = new Boxy(‘#preview-static-block’, {  
  78.                      title: ‘ ’,  
  79.                      modal: true,  
  80.                      fixed: true,  
  81.                      show: false,  
  82.                      center: true,  
  83.                      cache: false,  
  84.                      closeText:   
  85.                  });  
  86.                    
  87. </script>  

Abstract class are a feature of PHP (OOPs)

Abstract classes are a feature of PHP object-oriented programming (OOP) and the source of confusion when considered versus an Interface.
Main difference between interface and abstract class is:
• Child class can implement multiple interfaces but extend only a single abstract class.
• If multiple inheritance is not required then people often go with abstract classes.
• Abstract Class provide the option of later adding base functionality within the abstract class.
Importance of abstract class:
A abstract class provide the functionality to concrete base class function as well as abstract function which is must be implemented by child class.
Abstract Method

An abstract method would be written like any other method except it contains ‘abstract’ at the beginning. When an abstract method is declared in the parent class, the child classes must their own function under the same name and signature as declared in the parent class.

  1. Example:  
  2. abstract class TestAbstract  
  3. {  
  4.       
  5.     abstract function getHello();  
  6. }  
  7. Class driveCl extends TestAbstract {  
  8.     protected function getHello() {  
  9. echo ‘hello’;     
  10. }  
  11. }  
  12. $objnew driveCl();  
  13. $obj-> getHello();  
  14. Result ‘hello’;  

Featured of Abstract class:
1. Single inheritance. Child classes can extend only one class at a time.
2. Abstract classes cannot be instantiated — no new TestAbstract ();
3. Abstract classes can define class variables of type const only.
4. Abstract class A can be extended by another abstract class B. Abstract class B can implement none or any of the abstract functions in A.
5. In the previous case, a child class C which extends abstract class B must implement all abstract functions in B as well as the abstract functions in A which have not already been implemented in B.
6. The signature of the concrete functions and abstract functions must be the same.
7. The visibility of functions in the child classes must be the same or less restrictivethan the parent class.

How to create another controller under controller folder in Magento

Like we want to create a new group of controller class under a module controller folder.
mymudle/controllers/indexControler.php
We want to create another folder iunder controller ‘render’ and create new controller class under newly created folder.
mymudle/controllers/rednder/carusalController.php
then url would be
mywebsite/module_name/controller_render/action

Step 1: First we will create a controller file under controllers folder.

mymudle/controllers/renderContrioller.php

  1. <?php  
  2. class NS_MN_RenderController extends Mage_Core_Controller_Front_Action  
  3. {  
  4.       
  5. }  
  6. ?>  

Step 2: We will create folder same name as above controller file crearted.

mymudle/controllers/rednder

Step 3: We will create Carousel controller under render folder.
  1. <?php  
  2. class NS_MN _Render_CarouselController extends Mage_Core_Controller_Front_Action  
  3. {  
  4.      /** 
  5.      * Get test of particular static block 
  6.      */  
  7.     public function indexAction()  
  8.     {  
  9.         $this->loadLayout();  
  10.         $this->renderLayout();  
  11.     }  
  12. }   

jquery difference between parent and parents

Hello friend s, Now I am discussing a topic here clarify the difference between parent() and parents().
JQuery provide two wonderful method to get parents element information of selected element.

Given the following HTML:

  1. <html>  
  2. <body>  
  3. <div class=”one”>  
  4. <div class=”two”>  
  5. <p><span>Some text</span></p>  
  6. </div>  
  7. </div>  
  8. </body>  
  9. </html>  

If you want find the span parent element then you write simple code like:

$(‘span’).parent()
It will return [p] tag object.

Whereas if you call parents () method :

$(‘span’).parents()
Then you will get all above element from current selected element such as jQuery object is [p, div.two, div.one, body, html]
So main difference between parent() and parents is parent element while parents() will select all elements straight up the DOM tree.

jQuery also provide some filter method for filter search.

Like if you want find only div element then you will write code:

$(‘span’).parents().filter(‘div’)
OR
$(‘span’).parents(‘div’)
This would result in [div.two, div.one].

if you want only first div in the parent DOM then you will write:

$(‘span’).parents(‘div:eq(0)’)
Result would be ‘div.two’.

How to add dynamic id of all image in a template

  1. jQuery(document).ready(function() {  
  2.     var i = 1;  
  3.     jQuery(‘.list img’).each(function () {  
  4.         jQuery(this).attr(‘id’‘image-’ + i);  
  5.         i = i + 1;  
  6.     });  
  7. });  

How to create hour drop down list in PHP

Below is simple code for generate Hour dropdown list in php.

  1. public function getHourHtml()  
  2.     {  
  3.         $default = $this->getActivateAtHour();  
  4.         $html = ‘<select name=”activate_at_hour” class=”mini”>’;  
  5.         for ($i = 1; $i <= 12; $i++) {  
  6.             $html .= sprintf(‘<option value=”%s” %s>%s</option>’,   
  7.                 $i,   
  8.                 $i == $default   
  9.                     ? ‘selected’   
  10.                     : ,   
  11.                 strtoupper($i));  
  12.         }    
  13.         $html .= ‘</select>’;  
  14.   
  15.         return $html;  
  16.     }     

How to create meridian dropdown list in PHP

Now we have demonstrated how to create meridian dropdown and return the dropdown as an html.

  1. public function getMeridiemHtml()  
  2.     {  
  3.         $default = $this->getActivateAtMeridiem();  
  4.         $html = ‘<select name=”activate_at_meridiem” class=”mini”>’;  
  5.         foreach (array(‘am’‘pm’as $m) {  
  6.             $html .= sprintf(‘<option value=”%s” %s>%s</option>’,   
  7.                 $m,   
  8.                 $m == $default   
  9.                     ? ‘selected’   
  10.                     : ,  
  11.                 strtoupper($m));  
  12.         }    
  13.         $html .= ‘</select>’;  
  14.   
  15.         return $html;  
  16.     }