Header menu

_________________________________________________________________________________

Wednesday 26 February 2014

How to create a link on button tag in html ?


Button with link

Sometimes we need to create link on button in html . To do so we just need to add button tag on text of <a> tag.

In below line of code we have applied <button> tag on text of <a> tag.

<a href="http://www.codesplanet.blogspot.com" target="_parent"><button>Click me !</button></a>

Now we have a button with link on it 

Thursday 20 February 2014

Close button not showing on jquery ui dialog form


This problem might occur when you call jquery ui css file local system. The problem is your script is able to findat provided url given in css file. To fix the error you need to made change to two lines in css file.
Change the text with in red  at line number 823 and 840 with

http://1.bp.blogspot.com/-IngEXFSQ2y0/UwYnr4vsTGI/AAAAAAAAAMY/iHmyu11rGCM/s1600/close.gif

Corrected statement will be :

background: #dadada url(http://1.bp.blogspot.com/-IngEXFSQ2y0/UwYnr4vsTGI/AAAAAAAAAMY/iHmyu11rGCM/s1600/close.gif ) 50% 50% repeat-x;
1. At line number 823

.ui-widget-header .ui-state-default {
border: 1px solid #d3d3d3;
background: #e6e6e6 url(images/ui-bg_glass_75_e6e6e6_1x400.png) 50%   50% repeat-x;

font-weight: normal;
color: #555555;
}
2. At line number number 840
.ui-widget-header .ui-state-focus {
    border: 1px solid #999999;
    background: #dadada url(images/ui-bg_glass_75_dadada_1x400.png) 50% 50% repeat-x; 
     font-weight: normal;
    color: #212121;
}


Saturday 15 February 2014

Multiple file upload with form submit using ajax


File upload  in ajax form is always a headache to newbie. Today i am sharing a simple tutorial to upload files in ajax. What you have to do is ,just copy two files one containing form and other receiving posted data and run them .I have tried it to keep it simple so please ignore the design.

form.php
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="http://github.com/malsup/blockui/raw/master/jquery.blockUI.js?v2.31"></script>
<script type="text/javascript" src="http://github.com/malsup/form/raw/master/jquery.form.js?v2.36"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('form').ajaxForm({
    });
    $("#add_file").on("click",function(){
        var ranNum = Math.round(Math.random()*50);
        $("#fileone").append("<div id='file"+ranNum+"'><input type='file' name='file"+ranNum+"' /><button type='button' class='rem' id='rem_file"+ranNum+"'>X</button></div>");
        p_id=ranNum;
    });
    $(document).on("click",".rem",function(){
        var id=$(this).attr('id');
        var ret = id.split("_");
        $("#"+ret[1]).remove();
    });   
});
</script>

Thursday 6 February 2014

An array contains number from 1 to 10 . One number is missing. Find the number missing with O(n) complexity.

<?php
  $arr=array(10,1,4,5,7,8,9,3,2);
  $sum=0;
  for($i=0;$i<=10;$i++){
      $sum=$sum+$i;
    }
   $newsum=0;
  foreach($arr as $arr){
      $newsum=$newsum+$arr;
    }
  $missingnumber=$sum-$newsum;
  echo  $missingnumber;
?>

Explain difference between delete, truncate and drop command in Mysql.

 DELETE

DELETE command in mysql is used to remove rows from a table. We can use where clause  to only remove some rows. If we do not  specify any where clause , all rows will be removed.DELETE operations can be rolled back.
 Syntax : DELETE FROM table_name WHERE column_name=value;

TRUNCATE

TRUNCATE command in mysql removes all rows from the table. The operation cannot be rolled back and no triggers will be fired.  TRUNCATE is faster than DELETE.
Syntax:  TRUNCATE TABLE table_name;

DROP

The DROP command in  mysql removes the table from the database. All the table rows, indexes and privileges will  be removed. No triggers will be fired and the operation cannot be rolled back.
Syntax:  Drop TABLE table_name;

Point to note :
 DELETE operations can be rolled back on the other hand  DROP and TRUNCATE operations cannot be rolled back.

Tuesday 4 February 2014

Stop/Hold output before sending of header


ob_start()

Normally, the output  starts as soon as your first "echo" comes  or first non-PHP content. Once output starts, we cannot send headers . So to tackle this we use output buffering we is disabled by default.  

To create a new output buffer and start writing it, we call ob_start(). There are two ways to end a buffer :-

1.  ob_end_flush()
      It ends the buffer and sends all data to output

2.  ob_end_clean()
      It ends the buffer without sending it to output.

Consider the following script:

<?php
    ob_start();
    echo
"Hello One!\n";
    
ob_end_flush();

    
ob_start();
    echo
"Hello Two!\n";
    
ob_end_clean();

    
ob_start();
    echo
"Hello Three!\n";
?>

Output :  Hello One! Hello Three!

This script will output "Hello One" because the first text is placed into a buffer then flushed with ob_end_flush().

The "Hello Two" will not be printed out, although it is echoed, because it is placed into a buffer which is cleaned using ob_end_clean() and not sent to output.

Finally, the script will print out "Hello Three" because PHP automatically flushes  output buffers when it reaches at the end of a script.

Monday 3 February 2014

Inner join between more than two tables


Inner Join between more than two tables

To explain this lets take an example.
We have three table table1,table2,table3 .
table1 has primary key pk on which we want to take join of three table.

Query :  

SELECT * FROM table1
INNER JOIN table2 ON table1.pk=table2.table1Id
INNER JOIN table3 ON table1.pk=table3.table1Id