Monday, 9 May 2011

Check all checkboxes through JQuery

$(document).ready(function(){
$(".checkall").click( function() {
  $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', true);
})

})

Find any part of string in another string & manipulate accordingly

<?php
$string = 'www.google.com';//string
$ss = strpos($string,'http://');//cheking whether the part of string exist in full string or not
if($ss!==false)//if exists
{
  $string = $string;
}
else
{
  $string = 'http://'.$string;
}
echo $string;//final string.
?>

Friday, 6 May 2011

Regular Expression in MySQL

WHERE phone REGEXP '[(]435[)]';

would return only phone numbers with (435), such as "1(435)555-5555".

GroupConcat in MySql directly gives the output in required format as string

Language is column name and CountryLanguage is table name

English
Hindi
Punjabi
Chinese

SELECT GROUP_CONCAT(Language) As Languages FROM CountryLanguage;

Output will be:

English,Hindi,Punjabi,Chinese

SELECT GROUP_CONCAT(Language SEPARATOR '-') As Languages FROM CountryLanguage;
Output will be:


English-Hindi-Punjabi-Chinese

Wednesday, 4 May 2011

Get data through JSON

//Javascript Code

<script language="javascript" type="text/javascript" src="jquery.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("#sample").click(function(){

  $.ajax({
      type:'GET',
      url :'testAjax.php',
      success:function(msg)
      {
        var jvar = eval('(' + msg + ')');
        alert(jvar.a);
        alert(jvar.b);
      }
  })
})
})
</script>

//Sample Div

<div id="sample" style="cursor:pointer;>here</div>


//PHP request page

<?php
$arr = array('a'=>5,'b'=>8);
$encodedVal = json_encode($arr);
echo $encodedVal;
?>

Fibonacci series in PHP

<?php

$first = 0;
$second = 1;
$n = 20; // number of times you want to print the value
print $first.'<br>'; // print the first value
for($i=1;$i<$n;$i++)
{
  $final = $first + $second;
  $first = $second;
  $second = $final;
  print $final.'<br>';
}

?>

Sunday, 1 May 2011

To get the file extension

$filename = Name of the file

function findfileextension($filename)
{
     if(strpos(strrev($filename), ".")===false)
     {
            return "";
     }
     else
     {
         $ipos = strpos(strrev($filename), ".");
         $ext = substr($filename, -1*$ipos);
       
         return $ext;
     }
}