Instant Character Count jQuery

How To's

Twitter like instant character count in jquery

Read More..
Facebook Features

Facebook Features

In enhancing user experience, Facebook today launched new functionality Send button.

Read More..
Social Media

Social Media

Some days back Facebook introduces a new migration tool “Profile To Business Page Migration”, which converts personal profile to business profile and turn all their friends into fans.

Read More..
Twitter Features

Twitter Features

Now it’s time for you to secure your twitter account. Couple of weeks ago, twitter moved one step further in their security level for their users and announces HTTPS service by one check setting change.

Read More..
Security Tips

Security Tips

Well, in today’s world most of us are using social networking sites in our daily life, but how many people know that they are secured while using these sites. Most of the leading networking sites like Facebook, Twitter, LinkedIn, etc.

Read More..
  • Tuesday, May 29, 2012
  • | Kathirason Asokan 0
  • Handy newsletter signup in javascript with ajax and PHP



    Ajax is a popular technology in web development with the combination of Javascript and DOM, Ajax will do wonders. Here I’m not talking about ajax technology, just explaining how newsletter signup can be done with ajax and core javascript along with PHP. In this example I have used onclick javascript event to call an Ajax request.

    Create an HTML page, say for example newsletter.html which is the user communication page and ajax.js javascript page for handling client side scripting and finally ajax.php for communicating with server.

    Add the below HTML Code in newsletter.html

    <form name="formNewsletter" id="formNewsletter" action="" method="post"><input type="text" name="email" id="email" value="" /><input type="button" name="btnSubmit" id="btnSubmit" value="Signup" onclick="ajaxRequest('newsletter_signup','divSignupMessage');"/></form><div id="divSignupMessage">Submit your email address to receive the latest updates</div>; 

    Here "newsletter_signup" is an unique process name, which i have used for handling the request based on the process name. And div id divSignupMessage used for displaying the output received from server.

    Now create another file called  ajax.js and add the below code into it.

    //Ajax Request Handler
    function xmlhttpPost(url,method,divname,qstr){
    var 
    xmlHttpReq false;
    var 
    self this;
    // Mozilla/Safari
    if (window.XMLHttpRequest){
    self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject){
    self.xmlHttpReq = new ActiveXObject('Microsoft.XMLHTTP');
    }
    self.xmlHttpReq.open(methodurltrue);
    self.xmlHttpReq.setRequestHeader('Content-Type''application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function(){
    if (
    self.xmlHttpReq.readyState == 4){
    updateDiv(self.xmlHttpReq.responseText,divname);//div update function call
    }
    }
    self.xmlHttpReq.send(qstr);
     }

    //Updating output
    function updateDiv(txtvalue,divname){
    if(
    divname){
    document.getElementById(divname).innerHTML='';
    document.getElementById(divname).innerHTML=txtvalue;
    }
    }


    function 
    ajaxRequest(process,divname){
    if(
    process =='newsletter_signup'){
    email    document.getElementById('email').value;
    qstr     'p=' escape(process) + '&email=' escape(email);
    xmlhttpPost('ajax.php','POST',divname,qstr);
    }
    }

    Finally add below PHP Code in ajax.php file.

    $process trim($_REQUEST["p"]);
    $output "";

    if(
    $process == "newsletter_signup"){$email mysql_real_escape_string(trim($_REQUEST["email"]));
    $email_validation ereg("^[-A-Za-z0-9_]+[-A-Za-z0-9_.]*[@]{1}[-A-Za-z0-9_]+[-A-Za-z0-9_.]*[.]{1}[A-Za-z]{2,5}$"$email);

    if($email_validation<1){//Email validation error message
    $output "Please enter valid email address";
    }elseif(
    $email_validation>=1){ //Already exist email error message
    $sql "SELECT `email` FROM `newsletter` WHERE `email`=".$email." LIMIT 1";
    $res mysql_query($sql);
    $tot mysql_num_rows($res);

    if(
    $tot>0){
    $output "Email address already exist";
    }else{

    $output "TRUE";
    }
    }
    echo 
    $output;
    exit;
    }
    //End 

    Check out the online example and download the working example.


    [ Read More ]
  • Friday, May 25, 2012
  • | Kathirason Asokan 0
  • Add minutes or hours to current time mysql


    Writing a SQL query is always interesting, and for me it’s never boring task. Recently I was developing a CRM for my company, In that I need to send mail to the users who have scheduled their task as a reminder so I taught of using cron job for the same.Well now I need to fetch the users to schedule the mail, here is the challenge; I have to set the cron job to run the file every 15 minutes, so I have to take out the users from current time to next 15 minutes.

    We can achieve this by PHP, but I want to do it via mysql itself. After quick googling, I found a function called DATE_ADD().


    Syntax:

    DATE_ADD(date_time,INTERVAL expr type)

    My Query:

    SELECT * FROM table_task WHERE field_remainder BETWEEN NOW(AND DATE_ADD(NOW(), INTERVAL 15 MINUTE)

    So adding 15 minutes to the current time becomes easier now by using the DATE_ADD() function. Likewise you can also add days to the date. Check here for more detailed information on DATE_ADD() function.

    [ Read More ]
  • Saturday, May 05, 2012
  • | Kathirason Asokan 0
  • Sorting Alphanumeric values in MySQL


    Yesterday I got query from a visitor of my blog, he wants to do a sorting were the data stored in the field is alphanumeric. Normally this type of sorting we call it as "Natural Sort". He also gave me the structure of the data.



    Data
    Here is an example how the column looks.

    trip_id
    TRPAN1000
    TRPAN999
    TRPAN1002
    TRPAN998

    Now he wants to sort the above column in following order.

    trip_id
    TRPAN1002
    TRPAN1000
    TRPAN999
    TRPAN998

    Problem

     SELECT trip_id FROM test_table ORDER BY trip_id DESC 

    trip_id
    TRPAN1000
    TRPAN1002
    TRPAN998
    TRPAN999

    Sorting by alphanumeric column with normal ORDER BY query will end in unexpected result.

    Solution
    Since first 5 characters are common in trip_id field, I have used SUBSTR function to remove those characters and then used CAST function to sort the integer values which is in the form of varchar datatype.

     SELECT trip_id FROM test_table ORDER BY CAST(SUBSTR(trip_id,6) AS SIGNEDDESC 

    Here is our expected result.

    trip_id
    TRPAN1002
    TRPAN1000
    TRPAN999
    TRPAN998


    [ Read More ]
  • Thursday, April 05, 2012
  • | Kathirason Asokan 4
  • Google adds punctuation symbols into search


    Google the search giant has tweaked their search technique by adding punctuation symbols into the search queries. Until now, We all know that Google ignore punctuation symbols like "%", "$", "\", ".", "@", "#", and "+". But this has changed now, Google has started indexing punctuation symbols.

    As a blogger this is a good news for me and all those who use twitter and other social media platform for getting traffic to their websites, because we use '@' tag along with the name for representing a person in webpages and in comment section. Likewise we also use '#' tag for keywords, as we use more frequently in twitter, now google starts indexing those keywords and names. This will also improve our personal profile.

    Google official search blog stats that, they have also made some more changes in tweaking their search technique for better performance.

    Here is an example for, how google performing with @ symbol.


    [ Read More ]
  • Friday, March 16, 2012
  • | Kathirason Asokan 1
  • Convert VARCHAR as INT for sorting in MYSQL


    Today i was working on a database which was more than 10 years old. My task is to fetch records form table and display based on sorting order. Here my problem is sorting column was defined as VARCHAR and values stored in are Integers.


    [ Read More ]

    About Me

    My Photo
    Kathirason Asokan
    I'm a practical guy. I blog about technical stuffs, social cause and kids related information. I love writing code in PHP, and spending time with friends. My hobbies are blogging, surfing internet, juggling etc.,
    View my complete profile
    IndiBlogger - The Largest Indian Blogger Community
     
    Copyright (c) 2011 - 2013 techispeaks.com. All rights reserved the content is copyrighted to Kathirason Asokan
    Creative Commons License