article

Friday, August 2, 2013

Passing array of checkbox values to php through jQuery

Passing array of checkbox values to php through jQuery 
 
//index.hmtl
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script type="text/javascript">
                function doit() {
                        var p=[];
                        $('input.cb').each( function() {
                                if($(this).attr('checked')) {
                                        p.push($(this).attr('rel'));
                                }
                        } );
                        $.ajax( {
                                url:'process.php',
                                type:'POST',
                                data: {list:p},
                                success: function(res) {
                                        alert(res);
                                }
                        });
                }
        </script>

        <input type="checkbox" class="cb" rel="1"></input>Test 1<br />
        <input type="checkbox" class="cb" rel="2"></input>Test 2<br />
        <input type="checkbox" class="cb" rel="3"></input>Test 3<br />
        <a href="javascript:void(0)" onclick="doit()">Click</a>
//process.php
<?php
print_r(@$_POST['list']);
?>

Tuesday, July 30, 2013

Delete Confirmation using Javascript

Delete Confirmation using Javascript 
 
<script>
function confirmDelete()
{
    return confirm("Are you sure you wish to delete this entry?");
}
</script>
<a href="?action=delete&id=3" onclick="return confirmDelete();"> Delete this entry</a>

PHP Tutorial: Classes and OOP

PHP Tutorial: Classes and OOP 

 
<?php
//PHP Tutorial: Classes and OOP
//The first thing you do is to define the class:
class cow
{
}
//Next, we'll create our first function - this is defined exactly the same as if you were not using classes:
// First we define the class
class cow
{
    // Define the function moo() - no parameters    
    function moo()
    {
        // Define the variable
        $sound = 'Moooooo';
        return $sound;
    }
}
//create the new class object 'in' a variable
// Create new cow object
$daisy = new cow;
//then call the moo() function
echo $daisy->moo();

//If you put this code together then, you will get something like this:
// First we define the class
class cow
{
    // Define the function moo() - no parameters    
    function moo()
    {
        // Define the variable
        $sound = 'Moooooo';
        return $sound;
    }
}
// Create new cow object
$daisy = new cow;
echo $daisy->moo();

//Ex. more functions
// First we define the class
class cow
{
    var $eaten;

    // Define the function moo() - no parameters    
    function moo()
    {
        // Define the variable
        $sound = 'Moooooo<br />';
        return $sound;
    }
    function eat_grass($colour)
    {
        if ($colour == 'green')
        {
            // cow is happy
            $this->eaten = true;
            return $this->moo();
        }
    }

    function make_milk()
    {
        if ($this->eaten)
        {
            return 'Milk produced<br />';
        }
        else
        {
            return 'cow has not eaten yet<br />';
        }
    }
}

//call these functions and try out the new class
// Create the cow object daisy
$daisy = new cow;
echo $daisy->moo();
echo $daisy->make_milk(); // Cow has not eaten yet
$daisy->eat_grass('green');
echo $daisy->make_milk(); // Milk produced

//final version
// First we define the class
class cow
{
    var $eaten;

    // Define the function moo() - no parameters    
    function moo()
    {
        // Define the variable
        $sound = 'Moooooo<br />';
        return $sound;
    }
    function eat_grass($colour)
    {
        if ($colour == 'green')
        {
            // cow is happy
            $this->eaten = true;
            return $this->moo();
        }
    }

    function make_milk()
    {
        if ($this->eaten)
        {
            return 'Milk produced<br />';
        }
        else
        {
            return 'cow has not eaten yet<br />';
        }
    }
}

// Create the cow object daisy
$daisy = new cow;
echo $daisy->moo();

echo $daisy->make_milk(); // Cow has not eaten yet
$daisy->eat_grass('green');
echo $daisy->make_milk(); // Milk produced
?>

Saturday, July 27, 2013

Style a Select Box Using CSS

Style a Select Box Using CSS
 
<style>
.styled-select select {
   background: transparent;
   width: 268px;
   padding: 5px;
   font-size: 16px;
   line-height: 1;
   border: 0;
   border-radius: 0;
   height: 34px;
   -webkit-appearance: none;
   }
   .styled-select {
   width: 240px;
   height: 34px;
   overflow: hidden;
   background: url(down_arrow_select.jpg) no-repeat right #ddd;
  
   display:block;font-size:16px;outline:0 none;padding:.4em;text-shadow:0 1px 0 #fff;-moz-border-radius:.6em;-webkit-border-radius:.6em;border-radius:.6em;border:1px solid #aaa;color:#333;text-shadow:0 1px 0 #fff;
   }
</style>
<div class="styled-select">
   <select>
      <option>Male</option>
      <option>Female</option>
   </select>
</div>

Friday, July 26, 2013

PHP, jQuery and MySQL Search

PHP, jQuery and MySQL Search
//index.html
<style>
body{ font-family:Arial, Helvetica, sans-serif; }
*{ margin:0;padding:0; }
#container { margin: 0 auto; width: 600px; }
a { color:#DF3D82; text-decoration:none }
a:hover { color:#DF3D82; text-decoration:underline; }
ul.update { list-style:none;font-size:1.1em; margin-top:10px }
ul.update li{ height:30px; border-bottom:#dedede solid 1px; text-align:left;}
ul.update li:first-child{ border-top:#dedede solid 1px; height:30px; text-align:left; }
#flash { margin-top:20px; text-align:left; }
#searchresults { text-align:left; margin-top:20px; display:none; font-family:Arial, Helvetica, sans-serif; font-size:16px; color:#000; }
.word { font-weight:bold; color:#000000; }
#search_box { padding:4px; border:solid 1px #666666; width:300px; height:30px; font-size:18px;-moz-border-radius: 6px;-webkit-border-radius: 6px; }
.search_button { border:#000000 solid 1px; padding: 6px; color:#000; font-weight:bold; font-size:16px;-moz-border-radius: 6px;-webkit-border-radius: 6px; }
.found { font-weight: bold; font-style: italic; color: #ff0000; }
h2 { margin-right: 70px; }
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
    $(".search_button").click(function() {
        // getting the value that user typed
        var searchString    = $("#search_box").val();
        // forming the queryString
        var data            = 'search='+ searchString;
         
        // if searchString is not empty
        if(searchString) {
            // ajax call
            $.ajax({
                type: "POST",
                url: "do_search.php",
                data: data,
                beforeSend: function(html) { // this happens before actual call
                    $("#results").html('');
                    $("#searchresults").show();
                    $(".word").html(searchString);
               },
               success: function(html){ // this happens after we get results
                    $("#results").show();
                    $("#results").append(html);
              }
            });   
        }
        return false;
    });
});
</script>
<div id="container">
<div style="margin:20px auto; text-align: center;">
<form method="post" action="do_search.php">
    <input type="text" name="search" id="search_box" class='search_box'/>
    <input type="submit" value="Search" class="search_button" /><br />
</form>
</div>     
<div>
<div id="searchresults">Search results :</div>
<ul id="results" class="update">
</ul>
</div>
</div>
//do_search.php
<?php
//if we got something through $_POST
if (isset($_POST['search'])) {
    // here you would normally include some database connection
    include('db.php');
    $db = new db();
    // never trust what user wrote! We must ALWAYS sanitize user input
    $word = mysql_real_escape_string($_POST['search']);
    $word = htmlentities($word);
    // build your search query to the database
    $sql = "SELECT title, url FROM pages WHERE content LIKE '%" . $word . "%' ORDER BY title LIMIT 10";
    // get results
    $row = $db->select_list($sql);
    if(count($row)) {
        $end_result = '';
        foreach($row as $r) {
            $result         = $r['title'];
            // we will use this to bold the search word in result
            $bold           = '<span class="found">' . $word . '</span>';   
            $end_result     .= '<li>' . str_ireplace($word, $bold, $result) . '</li>';           
        }
        echo $end_result;
    } else {
        echo '<li>No results found</li>';
    }
}
?>

Username availability check using PHP and jQuery

Username availability check using PHP and jQuery
 
<?php

/* CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`username` varchar(150) NOT NULL,
`email` varchar(100) NOT NULL',
`pass` varchar(100)  NOT NULL',
PRIMARY KEY (`id`)
) */
//Username availability check using PHP and jQuery
//if we got something through $_POST
if (isset($_POST['user'])) {
    // here you would normally include some database connection
    include('db.php');
    $db = new db();
    // never trust what user wrote! We must ALWAYS sanitize user input
    $username = mysql_real_escape_string($_POST['user']);
    // build your query to the database
    $sql = "SELECT count(*) as num FROM users WHERE username = " . $username;
    // get results
    $row = $db->select_single($sql);
    if($row['num'] == 0) {
        echo 'Username <em>'.$username.'</em> is available!';
    } else {
        echo 'Username <em>'.$username.'</em> is already taken!';
    }
}
?>
<script>
$(function() {
$("#sub").click(function() {
    // getting the value that user typed
    var checkString    = $("#username_box").val();
    // forming the queryString
    var data            = 'user='+ checkString;
 
    // if checkString is not empty
    if(checkString) {
        // ajax call
        $.ajax({
            type: "POST",
            url: "do_check.php",
            data: data,
            beforeSend: function(html) { // this happen before actual call
                $("#results").html('');
            },
            success: function(html){ // this happen after we get result
                $("#results").show();
                $("#results").append(html);
            }
        });
}
return false;
});
});
</script>
<form action="do_check.php" method="post">
    <input id="username_box" class="search_box" name="username" type="text" />
    <input id="sub" type="submit" value="Check" />
</form>

Thursday, July 25, 2013

Using Sessions in WordPress Plugins

Using Sessions in WordPress Plugins 

In your theme/plugin

Add the next piece of code to your functions.php or plugin file to enable sessions:

/**
 * init_sessions()
 *
 * @uses session_id()
 * @uses session_start()
 */
function init_sessions() {
    if (!session_id()) {
        session_start();
    }
}
add_action('init', 'init_sessions');

PHP Multiple Atachment Send

PHP Multiple Atachment Send 


E-mail with Attachment
 <?php
if ($_SERVER['REQUEST_METHOD']=="POST"){

   // we'll begin by assigning the To address and message subject
   $to="somebody@example.com";
   $subject="E-mail with attachment";

   // get the sender's name and email address
   // we'll just plug them a variable to be used later
   $from = stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">";

   // generate a random string to be used as the boundary marker
   $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

   // now we'll build the message headers
   $headers = "From: $from\r\n" .
   "MIME-Version: 1.0\r\n" .
      "Content-Type: multipart/mixed;\r\n" .
      " boundary=\"{$mime_boundary}\"";

   // here, we'll start the message body.
   // this is the text that will be displayed
   // in the e-mail
   $message="This is an example";

   // next, we'll build the invisible portion of the message body
   // note that we insert two dashes in front of the MIME boundary 
   // when we use it
   $message = "This is a multi-part message in MIME format.\n\n" .
      "--{$mime_boundary}\n" .
      "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
      "Content-Transfer-Encoding: 7bit\n\n" .
   $message . "\n\n";

   // now we'll process our uploaded files
   foreach($_FILES as $userfile){
      // store the file information to variables for easier access
      $tmp_name = $userfile['tmp_name'];
      $type = $userfile['type'];
      $name = $userfile['name'];
      $size = $userfile['size'];

      // if the upload succeded, the file will exist
      if (file_exists($tmp_name)){

         // check to make sure that it is an uploaded file and not a system file
         if(is_uploaded_file($tmp_name)){
  
            // open the file for a binary read
            $file = fopen($tmp_name,'rb');
  
            // read the file content into a variable
            $data = fread($file,filesize($tmp_name));

            // close the file
            fclose($file);
  
            // now we encode it and split it into acceptable length lines
            $data = chunk_split(base64_encode($data));
         }
  
         // now we'll insert a boundary to indicate we're starting the attachment
         // we have to specify the content type, file name, and disposition as
         // an attachment, then add the file content.
         // NOTE: we don't set another boundary to indicate that the end of the 
         // file has been reached here. we only want one boundary between each file
         // we'll add the final one after the loop finishes.
         $message .= "--{$mime_boundary}\n" .
            "Content-Type: {$type};\n" .
            " name=\"{$name}\"\n" .
            "Content-Disposition: attachment;\n" .
            " filename=\"{$fileatt_name}\"\n" .
            "Content-Transfer-Encoding: base64\n\n" .
         $data . "\n\n";
      }
   }
   // here's our closing mime boundary that indicates the last of the message
   $message.="--{$mime_boundary}--\n";
   // now we just send the message
   if (@mail($to, $subject, $message, $headers))
      echo "Message Sent";
   else
      echo "Failed to send";
} else {
?>
<p>Send an e-mail with an attachment:</p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" 
   enctype="multipart/form-data" name="form1">
   <p>From name: <input type="text" name="fromname"></p>
   <p>From e-mail: <input type="text" name="fromemail"></p>
   <p>File: <input type="file" name="file1"></p>
   <p>File: <input type="file" name="file2"></p>
   <p><input type="submit" name="Submit" value="Submit"></p>
</form>
<?php } ?>

Sanitize Input Form

Sanitize Input Form

 
<?php
include('connect.php');
$conn = db_connect();
 
 function cleanInput($input) {
  $search = array(
   '@<script[^>]*?>.*?</script>@si',   // Strip out javascript
   '@<[\/\!]*?[^<>]*?>@si',            // Strip out HTML tags
   '@<style[^>]*?>.*?</style>@siU',    // Strip style tags properly
   '@<![\s\S]*?--[ \t\n\r]*>@'         // Strip multi-line comments
 );
  $output = preg_replace($search, '', $input);
  return $output;
 }

?>
<?
if(isset($_POST["submit"]))
{
 $_username = cleanInput($_POST["_username"]);
 $_password = md5($_POST["_password"]);  
 $sql_insert = "INSERT INTO tbl_admin(_username, _password) VALUES ('$_username', '$_password')";
 $result = mysql_query($sql_insert);
 echo "records save"; 
 //echo "<script>
 //   window.location='index.php';
 //    </script>";
 //
}
?>
<div style="padding-left:50px; font-weight:bold; font-size:18px; margin-bottom:20px; color:#ffffff">
 ADD NEW Users
</div>
<form name="subjadd" action="" method="post">
 <table width="96%" border="0" cellspacing="3" cellpadding="4">
  <tr>
   <th>User name:</th>
   <td><input name="_username" type="text" size="40"></td>
  </tr>
  <tr>
   <th>Password</th>
   <td><input name="_password" type="text" size="40"></td>
  </tr>
  <tr>
   <th></th>
   <td>
    <input type="submit" name="submit" value="Add New!">
</td>
  </tr>
 </table>
</form>

Public, Private and Protected - PHP OOP

Public, Private and Protected - PHP OOP 

Example 
 
<?php
//Public Visibility in PHP Classes
//Public methods or variables can be accessible from anywhere. It can be accessible from using object(outside the class), or inside the class, or in child class.
class test
{
public $abc;
public $xyz;
public function xyz()
{
}
}

$objA = new test();
echo $objA->abc;//accessible from outside
$objA->xyz();//public method of the class test
?>

<?php
//Private Visibility in PHP Classes
//only be accessible withing the class. Private visibility in php classes is used when you do not want your property or function to be exposed outside the class.
Class test
{
public $abc;
private $xyz;
public function pubDo($a)
{
echo $a;
}
private function privDo($b)
{
echo $b;
}
public function pubPrivDo()
{
$this->xyz = 1;
$this->privDo(1);
}
}
$objT = new test();
$objT->abc = 3;//Works fine
$objT->xyz = 1;//Throw fatal error of visibility
$objT->pubDo("test");//Print "test"
$objT->privDo(1);//Fatal error of visibility
$objT->pubPrivDo();//Within this method private function privDo and variable xyz is called using $this variable.
?>


<?php
//Protected Visibility in PHP Classes
//useful in case of inheritance and interface. Protected method or variable can be accessible either within class or child class.
class parent
{
protected $pr;
public $a
protected function testParent()
{
echo this is test;
}
}
class child extends parent
{
public function testChild()
{
$this->testParent(); //will work because it
}
}
$objParent = new parent();
$objParent->testParent();//Throw error
$objChild = new Child();
$objChild->setChild();//work because test child will call test parent.
?>

Saturday, July 13, 2013

Clearing File Input Values

Clearing File Input Values


 
<script type="text/javascript">
        function clearFileInput( id )
        {
            var elem = document.getElementById( id );
            elem.parentNode.innerHTML = elem.parentNode.innerHTML;
        }
    </script>

    <form method="post" enctype="multipart/form-data">
        <input type="file" name="myFile" id="fileInput1" />
        <input type="submit" name="s" value="Upload" />
    </form>
    <a href="javascript:clearFileInput( 'fileInput1' );">Clear File Input Value</a>

Get URL Parameters Using Javascript

Get URL Parameters Using Javascript

 
function getparamurl( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

var get_param = getparamurl('getid');
alert(get_param);
http://tutorial101.blogspot.com/index.html?getid=123

Tuesday, June 18, 2013

Validate password strength using jQuery

Validate password strength using jQuery

 
<style type="text/css">
#register {
    margin-left:100px;
}
 #register label{
    margin-right:5px;
}
 #register input {
    padding:5px 7px;
    border:1px solid #d5d9da;
    box-shadow: 0 0 5px #e8e9eb inset;
    width:250px;
    font-size:1em;
    outline:0;
}
 #result{
    margin-left:5px;
}
 #register .short{
    color:#FF0000;
}
 #register .weak{
    color:#E66C2C;
}
 #register .good{
    color:#2D98F3;
}
 #register .strong{
    color:#006400;
}
 </style>
<script type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(function() {
  
    $('#password').keyup(function(){
        $('#result').html(checkStrength($('#password').val()))
    }) 
  
    function checkStrength(password){
  
    //initial strength
    var strength = 0
  
    //if the password length is less than 6, return message.
    if (password.length < 6) {
        $('#result').removeClass()
        $('#result').addClass('short')
        return 'Too short'
    }
  
    //length is ok, lets continue.
  
    //if length is 8 characters or more, increase strength value
    if (password.length > 7) strength += 1
  
    //if password contains both lower and uppercase characters, increase strength value
    if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))  strength += 1
  
    //if it has numbers and characters, increase strength value
    if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/))  strength += 1
  
    //if it has one special character, increase strength value
    if (password.match(/([!,%,&,@,#,$,^,*,?,_,~])/))  strength += 1
  
    //if it has two special characters, increase strength value
    if (password.match(/(.*[!,%,&,@,#,$,^,*,?,_,~].*[!,",%,&,@,#,$,^,*,?,_,~])/)) strength += 1
  
    //now we have calculated strength value, we can return messages
  
    //if value is less than 2
    if (strength < 2 ) {
        $('#result').removeClass()
        $('#result').addClass('weak')
        return 'Weak'
    } else if (strength == 2 ) {
        $('#result').removeClass()
        $('#result').addClass('good')
        return 'Good'
    } else {
        $('#result').removeClass()
        $('#result').addClass('strong')
        return 'Strong'
    }
}
});
</script>
 <form id="register">
    <label for="password">Password:</label>
    <input name="password" id="password" type="password"/>
    <span id="result"></span>
</form>

Form validations with Javascript and HTML5

Form validations with Javascript and HTML5


Javascript Form

<script type="text/javascript">
function send(){
if(document.dataform.tx_name.value=="" || document.dataform.tx_name.value.length < 8)
{
alert( "Insert your name with more than 8 chars!" );
document.dataform.tx_name.focus();
return false;
}
if( document.dataform.tx_email.value=="" || document.dataform.tx_email.value.indexOf('@')==-1 || document.dataform.tx_email.value.indexOf('.')==-1 )
{
alert( "Insert an valid e-mail adress!" );
document.dataform.tx_email.focus();
return false;
}
if (document.dataform.tx_message.value=="")
{
alert( "Insert your message!" );
document.dataform.tx_message.focus();
return false;
}
if (document.dataform.tx_message.value.length < 50 )
{
alert( "Is necessary to use more than 50 chars in the message field!" );
document.dataform.tx_message.focus();
return false;
}
return true;
}
</script>
<form action="#" method="post" name="dataform" onSubmit="return send();" >
  <table width="588" border="0" align="center" >
    <tr>
      <td width="118"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Name:</font></td>
      <td width="460">
        <input name="tx_name" type="text" class="formbutton" id="tx_name" size="52" maxlength="150">
      </td>
    </tr>
    <tr>
      <td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">E-mail:</font></td>
      <td><font size="2">
        <input name="tx_email" type="text" id="tx_email" size="52" maxlength="150" class="formbutton">
      </font></td>
    </tr>
    <tr>
      <td><font face="Verdana, Arial, Helvetica, sans-serif"><font size="1">Message<strong>:</strong></font></font></td>
      <td rowspan="2"><font size="2">
        <textarea name="tx_message" cols="50" rows="8" class="formbutton" id="tx_message" input ></textarea>
      </font></td>
    </tr>
    <tr>
      <td height="85"><p><strong><font face="Verdana, Arial, Helvetica, sans-serif"><font size="1">
      </font></font></strong></p></td>
    </tr>
    <tr>
      <td height="22"></td>
      <td>
        <input name="Submit" type="submit"  class="formobjects" value="Send">
  
        <input name="Reset" type="reset" class="formobjects" value="Reset">
      </td>
    </tr>
  </table>
</form>   
HTML 5 Form
<form method="post" action="">
    <label for="name">Name: </label>
    <input id="name" type=text required name=name/>
<br />
    <label for="email">Email: </label>
    <input id="email" type=text required name=email/>
<input type=submit value="OK"/>
</form> 

Saturday, June 15, 2013

jQuery and ajax with Codeigniter

jQuery and ajax with Codeigniter

application\controllers\products.php
<?php
class Products extends CI_Controller{
 
 function __construct(){
  parent::__construct();
 }
 
 function index() {
        $this->load->view('products');
    }
 public function get_all_users(){

  $query = $this->db->get('products');
  if($query->num_rows > 0){
   $header = false;
   $output_string = '';
   $output_string .=  "<table border='1'>";
   foreach ($query->result() as $row){
    $name = $row->name;
    $output_string .= '<tr>';
    $output_string .= "<th>$name</th>"; 
    $output_string .= '</tr>';    
   }     
   $output_string .= '</table>';
  }
  else{
   $output_string = 'There are no results';
  }
   
  echo json_encode($output_string);
 }
 }
?>
application\views\products.php
<script language='JavaScript' type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<button type='button' name='getdata' id='getdata'>Get Data.</button>
<div id='result_table'></div>
<script type='text/javascript' language='javascript'>
$('#getdata').click(function(){
    $.ajax({
            url: '<?php echo base_url().'products/get_all_users';?>',
            type:'POST',
            dataType: 'json',
            success: function(output_string){
                    $('#result_table').append(output_string);
                } // End of success function of ajax form
            }); // End of ajax call 
 
});
</script>

Friday, June 14, 2013

Create a simple style css table

Create a simple style css table



 
<style>
.simple-style {border-top:1px solid #CFCFCF; border-left:1px solid #CFCFCF; border-right:0; border-bottom:0; width:100%;font-family: Arial, Helvetica, tahoma sans-serif; font-size:12px; line-height:1.6; color:#282828;}
.simple-style td, .simple-style th {border-right:1px solid #CFCFCF; border-bottom:1px solid #CFCFCF; text-align:center; padding:5px 0; width:20%;}
.simple-style th {background-color:#dedede; font-size:120%;text-shadow: 0 1px 0 #fff;}
.simple-style tr:nth-child(even) {background: #fff;}
.simple-style tr:nth-child(odd) {background: #F6F6F6;}
</style>
<div style="width:700px;">
<h3>SIMPLE STYLE TABLE</h3>
<table class="simple-style">
    <thead>
        <tr>
            <th scope="col">Country</th>
            <th scope="col">Area</th>
            <th scope="col">Official languages</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>United States of America</td>
            <td>9,826,630 km2</td>
            <td>English</td>
        </tr>
        <tr>
            <td>United Kingdom</td>
            <td>244,820 km2</td>
            <td>English</td>
        </tr>
        <tr>
            <td>India</td>
            <td>3,287,240 km2</td>
            <td>Hindi, English</td>
        </tr>
        <tr>
            <td>Canada</td>
            <td>9,984,670 km2</td>
            <td>English, French</td>
        </tr>
        <tr>
            <td>Germany</td>
            <td>357,021 km2</td>
            <td>German</td>
        </tr>
    </tbody>
</table>
</div>

CSS3 Techniques

CSS3 Techniques







 
<style type="text/css">
body {
 background-color: #D6E4FF;
}

.shadow1 {
 background-color: #eee; 
 padding: 10px;
 padding-left: 18px;
 padding-right: 18px;
 box-shadow: 0px 2px 4px rgba(0,0,0,0.7);
 -webkit-box-shadow: 0px 2px 4px rgba(0,0,0,0.7);
 -moz-box-shadow: 0px 2px 4px rgba(0,0,0,0.7);
 color: black;
 font-family: "Lucida Sans MS", "Lucida Grande", Helvetica, sans-serif;
 font-size: 10pt;
}
.shadow2 {
 background-color: #333; 
 padding: 10px;
 padding-left: 18px;
 padding-right: 18px;
 box-shadow: 0px 2px 6px rgba(255,255,153,0.7);
 -webkit-box-shadow: 0px 2px 6px rgba(255,255,153,0.7);
 -moz-box-shadow: 0px 2px 6px rgba(255,255,153,0.7);
 color: white;
 font-family: "Lucida Sans MS", "Lucida Grande", Helvetica, sans-serif;
 font-size: 10pt;
}


.round1 {
 background-color: #f99;
 border: solid 1px black;
 border-radius: 6px;
 -webkit-border-radius: 6px;
 -moz-border-radius: 6px;
 padding: 10px;
 padding-left: 18px;
 padding-right: 18px;
 color: black;
 font-family: "Lucida Sans MS", "Lucida Grande", Helvetica, sans-serif;
 font-size: 10pt;
}
.round2 {
 background-color: #333; 
 border-radius: 12px;
 -webkit-border-radius: 12px;
 -moz-border-radius: 12px;
 -webkit-border-top-left-radius: 59px 20px;
 -webkit-border-bottom-left-radius: 59px 20px;
 -moz-border-radius-topleft: 59px 20px;
 -moz-border-radius-bottomleft: 59px 20px;
 padding: 10px;
 padding-left: 18px;
 padding-right: 18px;
 color: white;
 font-family: "Lucida Sans MS", "Lucida Grande", Helvetica, sans-serif;
 font-size: 10pt;
}
.round3 {
 border: dashed 2px #093;
 -webkit-border-top-left-radius: 17px;
 -moz-border-radius-topleft: 17px;
 -webkit-border-bottom-right-radius: 17px;
 -moz-border-radius-bottomright: 17px;
 background-color: #ff9; 
 padding: 10px;
 padding-left: 18px;
 padding-right: 18px;
 color: black;
 font-family: "Lucida Sans MS", "Lucida Grande", Helvetica, sans-serif;
 font-size: 10pt;
}



.css5box2 {
 <!-- Baseline -->
 
 background-color: #fed; 
 border-top: solid 1px white;
 border-bottom: solid 1px #669;
 padding: 10px;
 padding-left: 18px;
 padding-right: 18px;
 color: black;
 font-family: "Lucida Sans MS", "Lucida Grande", Helvetica, sans-serif;
 font-size: 10pt;
 margin-bottom: 10px;
 border-radius: 8px;
 <!-- border radius -->
 -webkit-border-radius: 8px;
 -moz-border-radius: 8px;
 <!-- shadows -->
 -moz-border-radius: 8px;
 box-shadow: 0px 1px 3px rgba(0,0,0,0.7);
 -webkit-box-shadow: 0px 1px 3px rgba(0,0,0,0.7);
 -moz-box-shadow: 0px 1px 3px rgba(0,0,0,0.7);
 <!-- gradient -->
 background: -webkit-gradient(
            linear,
            center top, center bottom,
            color-stop(0%, #fffffa),
            color-stop(30%, #fed),
            color-stop(80%, #fed),
            color-stop(100%, #fffffa)
          );
 background: -moz-linear-gradient(
            top, #eef, #cce 30%, #cce 80%, #eef 100%
          );
 width:350px;   
}

.gradback {
 background-color: #eee; 
 background: -webkit-gradient(
            linear,
            center top, center bottom,
            color-stop(0%, #eef),
            color-stop(30%, #cce),
            color-stop(80%, #cce),
            color-stop(100%, #eef)
          );
 background: -moz-linear-gradient(
            top, #eef, #cce 30%, #cce 80%, #eef 100%
          );

 border-top: solid 1px white;
 border-bottom: solid 1px #669;
 padding: 10px;
 padding-left: 18px;
 padding-right: 18px;
 border-radius: 8px;
 -webkit-border-radius: 8px;
 -moz-border-radius: 8px;
 box-shadow: 0px 1px 3px rgba(0,0,0,0.7);
 -webkit-box-shadow: 0px 1px 3px rgba(0,0,0,0.7);
 -moz-box-shadow: 0px 1px 3px rgba(0,0,0,0.7);
 color: black;
 font-family: "Lucida Sans MS", "Lucida Grande", Helvetica, sans-serif;
 font-size: 10pt;
}
.css5box2 h3 {
 text-shadow: 0px 3px 3px rgba(0,0,0,0.2);
 color: #339;
}

input.styled {
 background-color: #eee; 
 background: -webkit-gradient(
            linear,
            center top, center bottom,
            color-stop(0%, #eee),
            color-stop(100%, #fff)
          );
 background: -moz-linear-gradient(
            top, #eee, #fff
          );

 border: solid 2px white;
 padding: 3px;
 padding-left: 7px;
 padding-right: 7px;
 border-radius: 4px;
 -webkit-border-radius: 4px;
 -moz-border-radius: 4px;
 box-shadow: 0px 1px 3px rgba(0,0,0,0.7);
 -webkit-box-shadow: 0px 1px 3px rgba(0,0,0,0.7);
 -moz-box-shadow: 0px 1px 3px rgba(0,0,0,0.7);
 color: black;
 text-shadow: 0px 1px 1px white;
 font-family: "Lucida Sans MS", "Lucida Grande", Helvetica, sans-serif;
 font-size: 10pt;
}
input.styled:focus {
 box-shadow: 0px 1px 6px rgba(0,64,255,0.7);
 -webkit-box-shadow: 0px 1px 6px rgba(0,64,255,0.7);
 -moz-box-shadow: 0px 1px 6px rgba(0,64,255,0.7);
 outline: none;
 -webkit-focus-ring-color: none;
}

input.roundbutton {
 background-color: #eee; 
 background: -webkit-gradient(
            linear,
            center top, center bottom,
            color-stop(0%, #eee),
            color-stop(100%, #ccc)
          );
 background: -moz-linear-gradient(
            top, #eee, #ccc
          );

 border: solid 2px white;
 padding: 10px;
 padding-left: 18px;
 padding-right: 18px;
 border-radius: 8px;
 -webkit-border-radius: 8px;
 -moz-border-radius: 8px;
 cursor: pointer;
 box-shadow: 0px 1px 3px rgba(0,0,0,0.7);
 -webkit-box-shadow: 0px 1px 3px rgba(0,0,0,0.7);
 -moz-box-shadow: 0px 1px 3px rgba(0,0,0,0.7);
 color: black;
 text-shadow: 0px 1px 1px white;
 font-family: "Lucida Sans MS", "Lucida Grande", Helvetica, sans-serif;
 font-size: 10pt;
}
input.roundbutton:active {
 border-width: 1px;
 margin-left: 1px;
 margin-right: 1px;
 -box-shadow: 0px 1px 1px rgba(0,0,0,0.8);
 -webkit-box-shadow: 0px 1px 1px rgba(0,0,0,0.8);
 -moz-box-shadow: 0px 1px 1px rgba(0,0,0,0.8);
 background: -webkit-gradient(
            linear,
            center top, center bottom,
            color-stop(100%, #eee),
            color-stop(0%, #ccc)
          );
 background: -moz-linear-gradient(
            top, #ccc, #eee
          );

}
</style>
<p><b>Shadows</b></p>
<p> <span class="shadow1">Shadow</span>   <span class="shadow2">Glow</span></p>
<p><b>Borders with Rounded Corners</b></p>
<p> <span class="round1">Round Corners</span>   <span class="round2">Round Corners</span>   <span class="round3">Round Corners</span></p>

<p><b>How to Style Boxes</b></p>
<div class="css5box2">
<h3>Lorem Ipsum Dolor</h3>
<p>Lorem ipsum dolor sit amet,  vurucelerisque tincidunt ac vel elit.</p>
</div>

<div>
<input type="text" value="I am a text field" size="43" class="styled" />
</div>

<p><b>Styling Forms</b></p>
<div style="height: 43px">
<input type="button" value="Click Me" class="roundbutton" />
</div>

Create CSS Testimonial

Create CSS Testimonial
<style>
.testimonial {
    margin: 0;
    background: #B7EDFF;
    padding: 10px 50px;
    position: relative;
    font-family: Georgia, serif;
    color: #666;
    border-radius: 5px;
    font-style: italic;
    text-shadow: 0 1px 0 #ECFBFF;
    background-image: linear-gradient(#CEF3FF, #B7EDFF);
 width:400px;
}

.testimonial:before, .testimonial:after {
    content: "\201C";
    position: absolute;
    font-size: 80px;
    line-height: 1;
    color: #999;
    font-style: normal;
}

.testimonial:before {
    top: 0;
    left: 10px;
}
.testimonial:after {
    content: "\201D";
    right: 10px;
    bottom: -0.5em;
}
.arrow-down {
    width: 0;
    height: 0;
    border-left: 15px solid transparent;
    border-right: 15px solid transparent;
    border-top: 15px solid #B7EDFF;
    margin: 0 0 0 25px;
}
.testimonial-author {
    margin: 0 0 0 25px;
    font-family: Arial, Helvetica, sans-serif;
    color: #999;
    text-align:left;
}
.testimonial-author span {
    font-size: 12px;
    color: #666;
}
</style>
<blockquote class="testimonial">
  <p>Nullam non wisi a sem semper eleifend. Pellentesque habitant morbi tristique senectus et netus et male</p>
</blockquote>
<div class="arrow-down"></div>
<p class="testimonial-author">adipiscin</span></p>

Sunday, June 9, 2013

Understanding PHP Functions

Understanding PHP Functions 

<?php 
function calculate($num1, $num2, $operation = '+')
{
    switch($operation)
    {
        case '+': // add
            return $num1 + $num2;
            break;
        case '-': // subtract
            return $num1 - $num2;
            break;
        case '*': // multiply
            return $num1 * $num2;
            break;
        case '/': // divide, make sure denominator is not zero
            return ($num2 == 0) ? 'Cannot divide by zero' : $num1 / $num2;
            break;
        default:  // Display error message for unknown operation ex 'a', 'b' etc.
            return 'Unkown Operation Fool!';
            break;
    }
}
?>
<html>
<body>
<?php
    echo '1 + 3 = ';
    echo calculate(1,3);
    echo '<br />';
    echo '9 x 5 = ';
    echo calculate(9,5,'*');
    echo '<br />';
    echo 'Division by zero test: ';
    echo calculate(10, 0, '/');
    echo '<br />';
?>
</body>
</html>

Removing index.php from URL in Codeigniter

Removing index.php from URL in Codeigniter

Go to your root folder: create .htaccess

# Customized error messages.
ErrorDocument 404 /index.php
 
# Set the default handler.
DirectoryIndex index.php
 
# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>

Related Post