Skip to main content

Posts

Showing posts with the label Web Development

CSS margin property - Clarification margin: 0 0 10px;

 In this post we will going to explain the CSS margin property  margin: 0 0 10px; The margin CSS property sets the margin area on all four sides of an element. It is a shorthand for margin-top, margin-right, margin-bottom, and margin-left. CSS margin short hand code can be a bit confusing at first. margin: 0 0 10px;  Top margin = 0 Right/Left margin = 0 Bottom margin = 10px or pixels margin: 30px;   //All four margins are 30px margin: 10px 40px;  //Top & Bottom margin = 10px, left & right = 40 margin: 10px 20px 30px; // top=10, left/right=20, bottom=30 margin: 10px 20px 10px 20px;  // Top=10, Right=20, Bottom=10, Left=10  

Best way to find duplicate records in a table on database

Method 1: The method will display group wise duplicate leads. SELECT     eabhyasa_id, eabhyasa_name, eabhyasa_email, eabhyasa_mobile,stage_name,count(*) no_of_records FROM rns_leads as L     left join rns_stages as S on S.stg_id= E.eabhyasa_stg_id GROUP BY eabhyasa_email, eabhyasa_mobile HAVING count(*) > 1  Method 2: The below method will display all duplicate leads SELECT L.eabhyasa_id, L.eabhyasa_fname, L.eabhyasa_email, L.eabhyasa_mobile,S.stg_name, case when E.eabhyasa_cp_type=0 then "-" when E.eabhyasa_cp_type=1 then "Fssess" when E.eabhyasa_cp_type=2 then "full" when E.eabhyasa_cp_type=3 then "part1" when E.eabhyasa_cp_type=4 then "part2" when E.eabhyasa_cp_type=5 then "part3" when E.eabhyasa_cp_type=6 then "part4" end as Payment_Stage FROM rns_leads L left join gti_stages as S on S.stg_id= E.eabhyasa_stg_id INNER JOIN ( SELECT eabhyasa_email, eabhyasa_mobile,count(*) no_of_records FROM gt

How to Select/Check all radio buttons using Jquery

Use below HTML code to Check all radio buttons <input type="radio" class="presnt_all" name="emp_attendance" id="emp_attendance" value="1"/>All Present <input type="radio" class="absent_all" name="emp_attendance" id="emp_attendance" value="2"/>All Absent <input type="radio" class="leave_all" name="emp_attendance" id="emp_attendance" value="3"/>All Leave <input type="radio" class="presnt_att" name="emp_attendance1" id="emp_attendance1" value="1" />Present <input type="radio" class="absent_att" name="emp_attendance1" id="emp_attendance1" value="2" />Absent <input type="radio" class="leave_att" name="emp_attendance1" id="emp_attendance1" value="3" />Leave

Remove www & force https from URL using htaccess

By Using below code we are able to remove www and force https from URL using htacces   RewriteEngine On   RewriteCond %{HTTP_HOST} ^www.greenrobot.com$ [NC] RewriteRule ^(.*)$ https://greenrobot.com/$1 [R=301,L]   RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]   Or   <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L] RewriteCond %{HTTPS} !=on RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] </IfModule>

Split a string and get last match in jQuery and Javascript

Method 1: str = "~test content ~thanks ok ~eabhyas.blogspot.com";    strFine =str.substring(str.lastIndexOf('~')); console.log(strFine ); Output: ~eabhyas.blogspot.com Method 2: str = "~test content ~thanks ok ~eabhyas.blogspot.com";    console.log(str.split('~').pop()); OR str = "~test content ~thanks ok ~eabhyas.blogspot.com";  var parts = str.split("~"); var what_you_want = parts.pop(); Output: eabhyas.blogspot.com Method 3: str = "~test content ~thanks ok ~eabhyas.blogspot.com";    arr = str.split('~'); strFile = arr[arr.length-1]; console.log(strFile ); Output: eabhyas.blogspot.com

Simple PHP function to update data in Mysql Database

The below simple php function is used to update data into MySql database with out manually filling the update mysql query with input filed names. Function: function update_Defined($table, $data, $condition){     // update('table', array_map('trim',$_POST),'id='.$_POST['p_id']);     global $db;     $query = "UPDATE `" . $table . "` SET ";     $fis = array(); $vas = array();        foreach ($data as $field => $val){         $fis[] = "`$field`";         $vas[] = "'" . mysqli_real_escape_string($db,$val) . "'";     }        foreach ($fis as $key => $field_name) {         $fields[$key] = $field_name;         if (isset($vas[$key])) {             $fields[$key] .= '=' . $vas[$key];         }     }        $query .= implode(',', $fields);     $query .= " WHERE " . $condition;     //echo $query;exit;     Query($query); } Form: <form action="" method=

Simple Function to Insert data into MySql database using PHP

The below simple php function is used to insert data into MySql database with out manually filling the insert mysql query with input filed names. Function: function insert_Defined($table, $array,$ins=''){   // insert('table', array_map('trim',$_POST));     global $db;     $query = "INSERT INTO" . ' ' . $table;     $fis = array(); $vas = array();         foreach ($array as $field => $val) {         $fis[] = "`$field`";         $vas[] = ($val != "NOW()") ? "'" . mysqli_real_escape_string($db,$val) . "'" : "NOW()";     }         $query .= "(" . implode(",", $fis) . ") VALUES (" . implode(",", $vas) . ")";     //echo $query;exit;     Query($query);if(!empty($ins)){$ins_id=mysqli_insert_id($db);return $ins_id;} } Form: <form action="" method="post" name="designation&

Calculate Number of working days in a month excluding weekends(Saturday and Sunday) using PHP

The below function is used to calculate number of working days in a month. Function Calling: $no_days= rns_countDays ($row['date'],array(0, 6)); Function: function rns_countDays($date, $ignore) {      //echo countDays(array(0, 6), start_date, end_date);     $count = 0;     $ndays=0;     $now=date("Y-m-d");     $month=date("m",strtotime($date));     $year=date("y",strtotime($date));            if($month==date("m") && $year==date('y')) { //Date diff month start date to current date         $from_date = new DateTime($year.'-'.$month.'-01');         $to_date = new DateTime($now);         $days_diff=$from_date->diff($to_date); //echo $days_diff->d;         $ndays=$days_diff->format("%a");         for($i=0;$i<$ndays;$i++){             $modif = $from_date->modify('+1 day');             $weekday = $from_date->format('w');             if(in_array($weekday, $igno

Split Text into Lines - SplitLines | Free jQuery Plugins

SplitLines is a lightweight jQuery plugin which allow you to split  block of text into  multiple lines using specific html tag(s) and defined width & line height .  SplitLines ( $.splitLines() ) is a jQuery plugin that splits new lines of wrapped text into their own HTML elements, allowing you to animate or operate on each line individually. Works with nested HTML tags as well. splitLines() takes a block of text and splits it up into separate lines based on the width of the box or a width passed to the function. Requirements jQuery 1.4.2 or later How to Split Text By Lines Include required libraries on page. <script src="//code.jquery.com/jquery.min.js"></script> <script src="jquery.splitlines.js"></script> HTML: Below is the sample text which need to split into lines. <div id="mycontent">     This is an <strong>example</strong> of some long text     that we want to split into lines. </div>   Jav

Beautiful Checkbox CSS - Custom Checkboxes using CSS

Today we are going to share awesome lightweight CSS plugin to beautify the default checkboxes. The beautiful-checkbox.css library allows you to beautify and change styles, sizes, and positions of the native checkbox inputs with pure CSS.

Get current filename with first parameter(Query String) from URL using PHP function

Today eabhyas come up with a Query String function. This function is useful to get the Query String from URL. This Function is used to get current filename with first parameter(Query String) from URL using PHP function . Function: function rns_QueryString_first($incomingURL){     preg_match('/[^&]+/', $incomingURL, $match);     return $outgoingURL = $match[0]; } Example: $path="property_add?id=3&aa=aa&b=123"; define('RNSFIFQ', rns_QueryString_first($path)); echo RNSFIFQ; Output: property_add?id=3

Remove Duplicate QueryStrings from URL using PHP

This simple PHP function is used to Remove Duplicate QueryStrings from URL. Function: function rnsQueryString_dupremov($qstring){     if(!empty($qstring)) {     $vars = explode('&', $qstring);     $final = array();     if(!empty($vars)) {         foreach($vars as $var) {             $parts = explode('=', $var);                 $key = $parts[0];             if(!empty($parts[1])) { $val = $parts[1]; } else {$val="";}                 if(!array_key_exists($key, $final) && !empty($val))                 $final[$key] = $val;         }     }     return http_build_query($final);     } else { return false; } } Example: $path="property_add.php?id=3&aa=aa&b=123&b=123&aa=aa"; define('RNSFIWQ', property_add.'?'.rnsQueryString_dupremov($_SERVER['QUERY_STRING']));  or define('RNSFIWQ', basename($_SERVER['SCRIPT_NAME'].'?'.rnsQueryString_dupremov($_SERVER['QUE

Country dropdown list - HTML select/dropdown snippet

Country dropdown list with country name as value: <!-- Country dropdown list by ahandy --!> <select>     <option value="Afghanistan">Afghanistan</option>     <option value="Albania">Albania</option>     <option value="Algeria">Algeria</option>     <option value="American Samoa">American Samoa</option>     <option value="Andorra">Andorra</option>     <option value="Angola">Angola</option>     <option value="Anguilla">Anguilla</option>     <option value="Antartica">Antarctica</option>     <option value="Antigua and Barbuda">Antigua and Barbuda</option>     <option value="Argentina">Argentina</option>     <option value="Armenia">Armenia</option>     <option value="Aruba">Aruba</option>     <option value="Aus

Highlight the navigation menu for the current page

JavaScript: <script src="JavaScript/jquery-1.10.2.js" type="text/javascript"></script> <script type="text/javascript">     $(function() {         // this will get the full URL at the address bar         var url = window.location.href;         // passes on every "a" tag         $(".topmenu a").each(function() {             // checks if its the same on the address bar             if (url == (this.href)) {                 $(this).closest("li").addClass("active");                 //for making parent of submenu active                $(this).closest("li").parent().parent().addClass("active");             }         });     });        </script> HTML Code: <div class="topmenu">   <ul class="nav">     <li><a href="index.html">Home</a></li>     <li><a href="about.html">About Us</a></li>

Populate Dropdown List with Array Values in PHP

The below PHP function used to Populate HTML Dropdown List from Array Values. Function : <?php function rnsdrop_Array($arr,$selids,$title='Select'){     print"<option value='0'>".$title."</option>";     foreach($arr as $id =>$name) {     if($selids==$id && $id!=0)         print "<option value=\"".$id."\" selected>".stripslashes($name)."</option>\r\n";     else if($id!=0)         print "<option value=\"".$id."\">".stripslashes($name)."</option>\r\n";     } } ?>   The below example explains how to generate dropdown list with array values using simple PHP function.   Example: <?php $arr=array(0=>'-',1=>'East','West','North','South'); rnsdrop_Array($prop_facing, @$row['prop_facing'],"Select Property Fac

Encode and Decode of data URLs using Base64 in PHP

base64_encode and base64_decode: (PHP 4, PHP 5, PHP 7) base64_encode — Encodes data with MIME base64 Syntax: string base64_encode ( string $data ) Encodes the given data with base64.   Example: <?php $str = 'eabhyas.blogspot.com'; echo base64_encode($str); ?> Output:   ZWFiaHlhcy5ibG9nc3BvdC5jb20= (PHP 4, PHP 5, PHP 7) base64_decode — Decodes data encoded with MIME base64 Syntax: string base64_decode ( string $data [, bool $strict = false ] ) Decodes a base64 encoded data . Example: <?php $str = 'ZWFiaHlhcy5ibG9nc3BvdC5jb20='; echo base64_decode($str); ?> Output:   eabhyas.blogspot.com Function : <? function sscb64ende($s,$t=0){     if($t==0){         $v=base64_encode($s);         $v = strtr($v, '+/=', '-_,');     } else {         $v = strtr($s, '-_,', '+/=');         $v=base64_decode($v);     } return $v; } ?>

Multidimensional Array Searching - Find key by specific value

Solution is based on the array_search() function. You need to use PHP 5.5.0 or higher. $userdb=Array ( (0) => Array     (         (uid) => '100',         (name) => 'Sandra Shush',         (url) => 'urlof100'     ), (1) => Array     (         (uid) => '5465',         (name) => 'Stefanie Mcmohn',         (pic_square) => 'urlof100'     ), (2) => Array     (         (uid) => '40489',         (name) => 'Michael',         (pic_square) => 'urlof40489'     ) ); Solution-1: function myfunction($products, $field, $value) {    foreach($products as $key => $product)    {       if ( $product[$field] === $value )          return $key;    }    return false; }   Solution-2: $key = array_search(40489, array_column($userdb, 'uid')); echo ("The key is: ".$key); //This will output- The key is: 2 The function array_search() has two arguments. The first one is the value that yo

Document Expired or Webpage has expired on back button

If you have a dinamic website and want to allow your visitors to use the back button after they sent a form with the post method, the best combination I found was: <?php header("Expires: Sat, 01 Jan 2000 00:00:00 GMT"); header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); header("Cache-Control: post-check=0, pre-check=0",false); session_cache_limiter("must-revalidate"); // and after you start the sessionsession_start(); ?> I try some combinations using header("Cache-Control: no-cache, must-revalidate"), but when clicking the back button, the last changes in the form back to their previous states. The combination above works fine with IE 6.x. I didn't test this with other browsers. When I try something like session_cache_limiter("nocache, must-revalidate") it doesn't work. The page only updates when I used the browser's refresh button. In dynamic web sites this is not g

CodeIgniter Top 50 Interview Questions and Answers

1) Explain what is CodeIgniter? Codeigniter is an open source framework for web application. It is used to develop websites on PHP. It is loosely based on MVC pattern, and it is easy to use compare to other PHP framework. 2) Explain what are hooks in CodeIgniter? Codeigniter’s hooks feature provides a way to change the inner working of the framework without hacking the core files. In other word, hooks allow you to execute a script with a particular path within the Codeigniter. Usually, it is defined in application/config/hooks.php file. The hooks feature can be globally enabled/disabled by setting the following item in the application/config/config.php file: $config[‘enablehooks’] = TRUE; 3) Explain how you will load or add a model in CodeIgniter? Within your controller functions, models will typically be loaded; you will use the function $this->load->model (‘Model_Name’); 4) Explain what helpers in CodeIgniter are and how you can load a helper file? In CodeIgniter,