Tuesday, November 22, 2011

Mysql if null Example

SELECT IFNULL(parent_id, 0) AS pid, COUN T(IFNULL(parent_id, 0)) AS ans_count FROM qa GROUP BY IFNULL(parent_id, 0)

Monday, November 21, 2011

Jquery plugin

http://www.sastgroup.com/jquery/240-plugins-jquery

Wednesday, November 16, 2011

Find move the files in Linux

Find move the file types Linux

find -name "*.jpg" exec mv {} images \;

MYSQl DATE ADD Nice Example

INSERT INTO `DB`.`tbl` (`id`, `filed1`, `filed2`, `filed2`, `start_date`, `expiry_date`, `status1`, `status2`, `status3`) VALUES (NULL, '2', '33', '8', NOW(), DATE_ADD(NOW(),INTERVAL 7 DAY), 'XXXX', 'Active', 'Active');

Tuesday, November 15, 2011

Very Important Date & time Diff queries in mysql

SELECT TIME_TO_SEC(TIMEDIFF('2007-01-09 10:24:46','2007-01-09 10:23:46'));

SELECT CONCAT(
FLOOR(HOUR(TIMEDIFF(MC.expiry_date,MC.start_date)) / 24), ' days ',
MOD(HOUR(TIMEDIFF(MC.expiry_date,MC.start_date)), 24), ' hours ',
MINUTE(TIMEDIFF(MC.expiry_date,MC.start_date)), ' minutes') as

Cross Side Validation script in PHP

    function crosssidescriptvalidation($keyvalue){
                    global $mosConfig_live_site;

    
                        
                        $keyvalue=strip_tags($keyvalue);
                        $keyvalue=utf8_decode($keyvalue);
                        $keyvalue=htmlspecialchars($keyvalue);
                        $keyvalue = str_replace("\"", "", $keyvalue);
                        $keyvalue = str_replace(">", "", $keyvalue);
                        $keyvalue = str_replace("\<", "", $keyvalue);
                        $keyvalue = str_replace(";:( )", "", $keyvalue);
                        $rediredtUrl=$mosConfig_live_site;                       
                        if(stristr($keyvalue,"<script>")){
                        
                         header("location:$rediredtUrl");
                        }
                        return $keyvalue;
    
    }

Monday, November 14, 2011

The INSERT INTO Method

The INSERT INTO Method

This method, as the heading suggests, uses the INSERT INTO T-SQL statement to move records from one table to another. This method is one of the easiest methods of transferring data. This method can not only be done between tables on the same server, but can also be done across servers.

To use this method, all you have to do is code an INSERT INTO statement that identifies the target table, and uses a SELECT statement to identify the data you want to copy from the source table. Let me show you an example. Say you have two tables TABLE1, and TABLE2, where both tables have exactly the some table structure and are in the same database. In this case, to copy all the rows from TABLE1 to TABLE2 you would use the following INSERT INTO statement:

INSERT INTO TABLE2 SELECT * FROM TABLE1

Now suppose you do not want to copy all the rows, but only those rows that meet a specific criteria. Say you only want to copy those rows where COL1 is equal to "A." To do this you would just modify the above code to look like this:

INSERT INTO TABLE2 SELECT * FROM TABLE1 WHERE COL1 = 'A'

See how simple it is to copy data from one table to another using the INSERT INTO method? You can even copy a selected set of columns, if you desire, by identifying the specific columns you wish to copy and populate, like so:

INSERT INTO TABLE2 (COL1, COL2, COL3) SELECT COL1, COL4, COL7 FROM TABLE1

The above command copies only data from columns COL1, COL4, and COL7 in TABLE1 to COL1, COL2, and COL3 in TABLE2.

This method can also be used to copy data from one database to another. To do this you just need to fully qualify (<database>.<owner>.<table name>) the source and target table names on the INSERT INTO statement to identify which database you want to use. You can copy data from one server to another the same way by using fully qualified linked server names (<linked_server>.<database>.<owner>.<table_name>).

Thursday, November 10, 2011

Nice jquery demo

http://www.aakashweb.com/resources/pages/demos/jquery-collapser/

Wednesday, November 9, 2011

How alter enum filed in mysql.

How alter enum filed in mysql.

ALTER TABLE tablename CHANGE filedname filedname ENUM('Active', 'Inactive') not null default 'Active';

Tuesday, November 1, 2011

Jquery & javascript Form validation

<html>
<head>

<style type="text/css">
body{

width:100%;


}
.container{
 border:2px solid red;
 width:550px;
 margin:250px 250px;
 padding:20px;
 
 
}
.trdiv{
overflow:hidden;
padding:10px;

}
.tddiv{
float:left;
width:150px;
padding:5px;

}
input[type=text]{
border:1px solid green;
border-right:10px solid green;
border-left:10px solid green;;
}
input[type=password]{
border:1px solid green;
border-right:10px solid green;
border-left:10px solid green;;
}
.header
{
    margin:10px 10px;
    color:red;
    font:bold;
}
</style>
<script type="text/javascript" src="jquery-1.6.4.js"></script>

<script type="text/javascript">

   $("document").ready( function(){
       
   
    $('#register').submit(function(){
   
    if(($('#unameid').val())==""){
        alert("Please Enter User name");
        $('#unameid').focus();
        return false;
    }
   

   
    return false;
}
);

}
);



function validate(){

var name,pass;
//name=document.validation.uname.value;
name=document.getElementById("unameid").value;
pass=document.getElementById("upass").value;
age=document.getElementById("age").value;
phone=document.getElementById("phone").value;
//name=document.getElementsByName("uname");
//alert(name[0].value);

var phone_ex=new RegExp("[^(+)|0-9-\(\)]");

//alert(name);
if(name=='' & pass=='')
{
   
    alert(" Please Enter the UserName & Password");
    document.getElementById("unameid").focus();
//    document.getElementById("unameid").select();
    return false;
   
}
if(name=='')
{
   
    alert(" Please Enter the UserName");
    document.getElementById("unameid").focus();
    return false;
   
}
if(pass=='')
{

    //document.getElementById("unameid").select();
   
    alert(" Please Enter the  Password");
    document.getElementById("upass").focus();
    return false;
   
}

if(phone=='')
{

    //document.getElementById("unameid").select();
   
    alert(" Please Enter the  phone number");
    document.getElementById("phone").focus();
    return false;
   
}
if (phone_ex.exec(phone)){
    alert(" Please Enter Validphone");
    document.getElementById("phone").focus();
    document.getElementById("phone").value="";
    return false;


}


return true;


}
</script>
</head>
<body>
<div class="container">
<div class="header"> Registration Form</div>
<form  id="register" name="validation" action="getvalues.php"  method="post" >
<!--<form name="validation" action="getvalues.php"  method="post" onsubmit="return validate()"> -->
<div class="trdiv">
<div class="tddiv">
Enter The user Name
</div>
<div class="tddiv">
<input type="text" name="uname" value="" id="unameid">
</div></div>
<div class="trdiv">
<div class="tddiv">
Enter the Password
</div>
<div class="tddiv"><input type="password" name="pass" value="" id="upass"></div>
</div>
<div class="trdiv">
<div class="tddiv">
Enter the Age
</div>
<div class="tddiv"><input type="text" name="age" value="" id="age"></div>
</div>
<div class="trdiv">
<div class="tddiv">
Enter the Phone
</div>
<div class="tddiv"><input type="text" name="phone" value="" id="phone"></div>
</div>
<div class="trdiv">
<div class="tddiv">&nbsp;</div>
<div class="tddiv">
<input type="submit" value="submit" name="submit">
</form>
</div>
</div>
</body>
</html>