Sunday, 22 June 2014

File Upload and Delete multiple rows by selecting checkboxes using PHP

Index Page :
<html>
<head></head>
<body>
<form name="frm" method="post" action="submit.php" enctype="multipart/form-data">
<table>
<tr>
<td> Student Name </td>
<td><input type="text" name="stu_name"/><td>
<tr>
<tr>
<td> Student Email </td>
<td><input type="text" name="stu_email"/><td>
<tr>
<tr>
<td> Student Phone </td>
<td><input type="text" name="stu_phone"/><td>
<tr>
<tr>
<td> Student Photo </td>
<td><input type="file" name="stu_photo"/><td>
<tr>
<tr colspan="2">
<td><input type="submit" value="submit data" name="submit"></td>
</tr>
</table>
</form>
<form name="frm1" method="post" action="submit.php" enctype="multipart/form-data">
<table>
<tr>
<td><input type="checkbox" name="check_all"/>
<td>ID</td>
<td> Name</td>
<td> Email</td>
<td> phone</td>
<td>photo </td>
</tr>
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("pan_test",$con);
$query = mysql_query("select * from stu_info");
while($row = mysql_fetch_array($query)){
$id = $row['id'];
$name = $row['name'];
$email = $row['email'];
$phone = $row['phone'];
$photo = $row['photo'];
echo "<tr>";
echo "<td><input type='checkbox' name='checkbox[]' value='$id'/></td>";
echo "<td>$name</td>";
echo "<td>$email</td>";
echo "<td>$phone</td>";
//echo "<td><img src='uploads/$photo'/><td>";
echo "</tr>";
}

?>
<tr colspan="2">
<td><input type="submit" value="submit data" name="submit1"></td>
</tr>
</body>
</html>

submit.php

<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("pan_test",$con);
if($_REQUEST['submit']){
$name= $_REQUEST['stu_name'];
if(empty($name)){
echo "missing";
}
$mail= $_REQUEST['stu_email'];
$phone=$_REQUEST['stu_phone'];
$photo= $_FILES['stu_photo'] ['name'];
$target = 'uploads/'.basename($_FILES['stu_photo'] ['name']);
move_uploaded_file($_FILES['stu_photo'] ['tmp_name'],$target);

$query = mysql_query("insert into stu_info(name,email,phone,photo) values('$name','$mail','$phone','$photo')");
header('location: index.php');
}
else if($_REQUEST['submit1']){
print_r($_REQUEST);
$checkbox= $_REQUEST['checkbox'];
for($i=0;$i<count($_REQUEST['checkbox']);$i++){
echo $id= $checkbox[$i];
$query = mysql_query("delete from stu_info where id=$id");

}
}

?>

Saturday, 21 June 2014

Database Connectivity using Type I - JDBC Driver in Java(J2SE)

What is JDBC?

  • JDBC(Java DataBase Connectivity) is used for connecting to different database by which user can shift from one database to another database very easily in platform independent manner.
  • JDBC contains set of functions & specification in the form of packages i.e.:
    • java.sql.*--Core SQL Package
    • javax.sql.*--Extended SQL Package
  • JDBC Driver act like an interface between front end application and back end database.
  • There are four types of JDBC Driver
    • Type I-ODBC(Open DataBase Connectivity) Bridge Driver 
    • Type II-Java Native Interface Driver
    • Type III-Net Protocol Driver
    • Type-IV-Native Protocol Drover
  • Type I Driver, there exist an implementation class by which user can be able to connect to different database.
  • This implementation class, named JdbcOdbcDriver.class is provided within rt.jar file.

Connecting to any Database:-

Step 1) Loading a Driver: 
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Step 2) Getting Connection: 
Connection con = DriverManager.getConnection("<URL>","<UserName>","<Password>");
Step 3) Create Statement Object:

Statement st = con.createStatement();
Step 4) Prepare a query and execute the query at backend database.

  • ResultSet rs = st.executeQuery("<SQL SELECT command>");
  • boolean flag = st.execute("<SQL Non-SELECT command>");
  • int x = st.executeUpdate("<SQL DML command>");

Step 5) Close all connections: 
st.close();
con.close();

Sample JDBC code for this demonstration:

import java.sql.*;

class DBConnectivity
{
public static void main( String [] args)
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:OracleDSN","scoot","tiger");
Statement st = conn.createStatement();
boolean flag = st.execute("create table student(ID varchar2(5), NAME varchar2(30), MARKS number(5))");
int x = st.executeUpdate("inser into stud values('101','Pallavi',879)");
ResultSet rs = st.executeQuery("<SELECT ID,NAME,MARKS from student>");
while (re.nwex())
{
logout("ID:-"+rs.getString(1)+"\t");
logout("NAME:-"+rs.getString(2)+"\t");
logout("MARKS:-"+rs.getInt(3)+"\n");
}
}

public void logout(String msg)
{
System.out.println(msg);
}

}

Note: Here "OracleDSN" is User Created DSN (Data Source Name), in Administrative Tools-->Data Source

Wednesday, 18 June 2014

Custom post type having same taxonomy in wordpress

Register custom post type and taxonomy

// function.php code

register_post_type('test1',
                      array(
                        'labels' => array(
                                     'name' => _x('Test1'),
                                     'singular_name' => _x('Test1'),
                                     'add_new' => _x('Add Test1', 'test1'),
                                     'add_new_item' => __('Add New Test1'),
                                     'edit_item' => __('Edit Test1'),
                                     'new_item' => __('New Test1'),
                                     'view_item' => __('View Test1'),
                                     'search_items' => __('Search Test1'),
                                     'not_found' =>  __('No Test1'),
                                     'not_found_in_trash' => __('No Test1 found in Trash'),
                                     'parent_item_colon' => ''
                                   ),
                        'public' => true,
                        'has_archive' => true,
                        'publicly_queryable' => true,
                        'query_var' => 'social_reporting',
                        'rewrite' => array('slug'=>'test1', 'with_front'=>false),
                        'capability_type' => 'post',
                        'hierarchical' => true,
'supports' => array('title', 'editor', 'page-attributes', 'thumbnail','taxonomy'),
'taxonomies' => array('post_tag')
                     
                 ));
 // custom post type for Video
  register_post_type('video',
                      array(
                        'labels' => array(
                                     'name' => _x('Video'),
                                     'singular_name' => _x('Video'),
                                     'add_new' => _x('Add Video', 'video'),
                                     'add_new_item' => __('Add New Video'),
                                     'edit_item' => __('Edit Video'),
                                     'new_item' => __('New Video'),
                                     'view_item' => __('View Video'),
                                     'search_items' => __('Search Video'),
                                     'not_found' =>  __('No Video found'),
                                     'not_found_in_trash' => __('No Video in Trash'),
                                     'parent_item_colon' => ''
                                   ),
                        'public' => true,
                        'has_archive' => true,
                        'publicly_queryable' => true,
                        'query_var' => 'video',
                        'rewrite' => array('slug'=>'video', 'with_front'=>false),
                        'capability_type' => 'post',
                        'hierarchical' => true,
'supports' => array('title', 'editor', 'page-attributes', 'thumbnail','taxonomy'),
'taxonomies' => array('post_tag')
                     
                 ));
}
add_action( 'init', 'initialize_autos_post_types' );
//custom taxonomy
register_taxonomy('pan_taxonomy', array('test1','video'),  array(
'label' => __('Add Categories'),
'singular_label' => __('Add Category'),
'hierarchical' => true,
'query_var' => 'pan_taxonomy',
'rewrite' => false,
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
        ));


To fetch custom taxonomy post 

// page.php code

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $post_type = array('test1','video');
        $loop = new WP_Query( array( 'post_type' => $post_type, 'posts_per_page' => -1, 'orderby'=>'date', 'paged'=>$paged ) );
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
       <article>
           <div class="right_blog_post">
                        <?php the_title( '<h2 class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h2>' ); ?>
<div class="entry-content">
                         <?php
                         the_excerpt();
                         ?>
    </div>
                    </div>
                </article>
  <?php endwhile; ?>


Monday, 16 June 2014

Create your own Autocomplete for textbox using JQuery

<html>
<head>
<style>
#auto_my_name
{
    border:1px solid #cccccc;
    width:auto;
    font-family:verdana, arial, helvetica, sans-serif;
    font-size:15px;
    height:auto;
    margin-top:0px;
    list-style:none;
    position: absolute;   /*display:none;*/
    padding: 0;
    background-color: #EAEAEA;
    z-index:1;
    box-shadow:6px 6px 8px #cccccc;
}

#auto_my_name li
{
    height:25px;
}

#my_name
{
    width:100px;
}

.services li.selected{
    background-color:#636060;
    color:#ffffff;
}
</style>


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript">
</script>
<script>

var my_name = ["Albert","Allen","Aladin","Nilesh","Dharmesh","Aakesh","Pankaj","Vijay","Manoj","Zahir","Mukesh","Kishor","Sachin","Rakesh"];
//Values for autocomplete list

$(document).ready(function(){

$("#my_name").unbind('keyup').keyup(function(e){
       
            if(e.keyCode == 13)
            {// Enter
                if ($(".services").is(":visible"))
                {
           
                    my_value = $(".selected").attr('id');
                    var my_id = $(".selected").attr("value");
                        $( "#my_name" ).val(my_value);
                    $(".services").empty();
                    $("#auto_my_name").slideUp();
                   
                }
                else
                {
                        $(".services").show();
                }
             }
       
            else if(e.keyCode == 38)
            { // up

                var selected = $(".selected");
                $(".services li").removeClass("selected");
                // if there is no element before the selected one, we select the last one
                if (selected.prev().length == 0)
                {
                    var child = selected.siblings().length + 1;
                $(".services li:nth-child("+child+")" ).addClass("selected");
                }
                else
                { // otherwise we just select the next one
                selected.prev().addClass("selected");
                }
            }
       
            else if(e.keyCode == 40)
            { // down
                var selected = $(".selected");
                $(".services li").removeClass("selected");
                if (selected.next().length == 0)
                {
                    $(".services li:nth-child(1)" ).addClass("selected");
                }
                else
                {
                    selected.next().addClass("selected");
                }
              }
             
              else
              {
                  call_name("my_name");
                 
              }
    });
       
});
   
   
function call_name(param)
{
    $(".services").empty();
    var temp_name = $("#"+param+"").val().toUpperCase().trim();
    var container = "";
    $("#auto_"+param+"").empty();
    if(temp_name != "")
    {
        if(param == "my_name")
        {
            var j = 0;
            for(i=0;i<my_name.length;i++)
            {
                container = my_name[i].toUpperCase().toString();
               
                if(container.indexOf(temp_name) >= 0)
                {
                   
                    if(j == 0){var selected = 'selected';}else{var selected = 'abc';}
                    $("#auto_"+param+"").append("<li class='listing "+selected+"' id='"+my_name[i]+"'>"+my_name[i]+"</li>");               
                    j++;
                }
                else
                {
                    $("#auto_"+param+"").hide();
                }
            }
        }
       
           
           
        $(".services li").mouseover(function()
        {
            $(".services li").removeClass("selected");
            $(this).addClass("selected");
        });
       
        $(".services li").click(function() {
            var my_value = $(this).attr('id');   
                selectOption(my_value, param);
                $(".product_class").empty();
            $(".services").empty();
        });
        var my_width = $("#"+param+"").width() + 5;
   
        $("#auto_"+param+"").width(my_width);
        $("#auto_"+param+"").width(my_width);
        $("#auto_"+param+"").slideDown();
       
       
        $("#"+param+"").unbind('blur').blur(function() {
            var my_value = $(".selected").attr('id');
            var my_id = $(".selected").attr("value");
            if($("#"+param+"").val() == "")
            {
                $("#"+param+"_id").val("");
            }
           
                selectOption(my_value, param, my_id);
            $("#auto_"+param+"").slideUp();
            $(".services").empty();
        });
       
           
    }
    else
    {
            $("#auto_"+param+"").slideUp();
    }
   
}

function selectOption(my_value, param, my_id)
{
   
    $( "#"+param+"" ).val(my_value);
    $( "#"+param+"_id" ).val(my_id);
    $("#auto_"+param+"").slideUp();
}

</script>
</head>
<input type="text" class="" id="my_name" value="" placeholder="Enter Name" autocomplete="off"/>
<ul class="services" id="auto_my_name">
                   
</ul>
</html>

Demo : 

A Simple way to Generate Random number in Java

Math.Random class

In Java Programming, Math.Randoms class generates random integers, doubles, longs and so on, in various ranges.

To generate a series of random numbers as a unit, you need to use a single Random object - do not create a new Random object for each new random number.

Following example shows this:




import java.util.Random;
/** Generate 10 random integers in the range 0..99. */

public class RandomInteger 

{

public static final void main(String... aArgs)
{
log("Generating 10 random integers in range 0..99.");
//note a single Random object is reused here Random randomObj = new Random();
for (int idx = 1; idx <= 10; ++idx)

{
int randomInt = randomGenerator.nextInt(100);

log("Generated : " + randomInt);
}
log("Done.");
}
private static void log(String aMessage)

{
System.out.println(aMessage);
}


}






Sunday, 15 June 2014

Hello World in Ember.js

Quick Start

>>> Step 1 : Create a html file and include files like ember.js and other dependencies.

    < script src='http://code.jquery.com/jquery-1.10.2.min.js'></script>
    <script src='http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-1.0.0.js'></script>
    <script src='http://builds.emberjs.com/tags/v1.3.0/ember.js'></script>

>>>Step 2: Create a view using handlebars template
It replaces body of html page
 
    <script type='text/x-handlebars' data-template-name='application'>
         <h1>{{appName}}</h1>
    </script>

>>>Step 3: Initialize ember application

   <script type='text/javascript'>
        App = Ember.Application.create({});
    </script>

>>>Step 4: Controller
Template is named as 'application'. So, the name of a controller should be 'ApplicationController'.

   <script type='text/javascript'>
        App.ApplicationController = Ember.Application.extend({
             message: 'Hello World'
        });
    </script>


Thursday, 12 June 2014

PHP Code for Locating Train stations, ATM's, Mall's and many things Nearby Using Google Map API

<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">

<style>
html, body, #googleMap
      {
        height: 100%;
        margin: 0px;
        padding: 0px;      
      }
     
.controls
      {
          position: absolute;
          z-index: 10;
        margin-top: 16px;
        margin-left:100px;
        border: 1px solid transparent;
        border-radius: 2px 0 0 2px;
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        height: 32px;
        outline: none;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
      }
     
 #country_name
      {
          box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
          position: absolute;
        background-color: #fff;
        padding: 0 11px 0 13px;
        margin-left:100px;
        margin-top:50px;
        border: 1px solid transparent;
        border-radius: 2px 0 0 2px;
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        height: 32px;
        outline: none;
        width: 400px;
        font-family: Roboto;
        font-size: 15px;
        font-weight: 300;
        text-overflow: ellipsis;
        z-index: 10;
      }
     
  #coord0
      {
          box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    position: absolute;
    z-index: 10;
    margin-left:100px;
        margin-top:760px;
        width:1000px;
      }
     
  #selection
      {
          background-color: #fff;
          box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
          position: absolute;
    z-index: 10;
    margin-left:100px;
        margin-top:30px;
      }
</style>
   
<script src="jquery-1.7.1.js" type="text/javascript">
</script>
<script src="jquery.fancybox-1.3.4.pack.js" type="text/javascript">
</script>
<!--script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false">
</script-->
<script type="text/javascript"
        src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=true&amp;libraries=places,drawing"></script>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<link rel="stylesheet" href="jquery.fancybox-1.3.4.css"/>

<script>
var map;
var infowindow;
var new_map;
var center;
var place_name = [];
var tubes;
var place_type;
var remove_marker = [];
////////////////////////////////////////
function initialize()
{
  mapProp = {
      center:new google.maps.LatLng(23.8989,12.4731),
      zoom:4,
      mapTypeId:google.maps.MapTypeId.ROADMAP
  };
 
 
    
    
    map = new google.maps.Map(document.getElementById("googleMap")
  ,mapProp);
 
  $(window).click(function(){
 
      place_type = $("#place_type").val();
  });
 
 
  $(window).keydown(function(event){
        if(event.keyCode == 13)
        {
            place_type = $("#place_type").val();
          ///event.preventDefault();
         //return false;
        }
      });
 
 
  //-----------------------------------------------------------------//
  var input = /** @type {HTMLInputElement} */(
      document.getElementById('country_name'));
 
  //map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
 
  var options = {
  types: ['(cities)'],
  componentRestrictions: {country: "in"}
 };
 
 
  var autocomplete = new google.maps.places.Autocomplete(input, options);
  //autocomplete.bindTo('bounds', map);
 
  var infowindow = new google.maps.InfoWindow();
  var marker = new google.maps.Marker({
    map: map
  });

 
  google.maps.event.addListener(autocomplete, 'place_changed', function() {
    infowindow.close();
    marker.setVisible(true);
   
    google.maps.event.addListener(autocomplete, 'resize');
    
    
    var place = autocomplete.getPlace();
    google.maps.event.trigger(map, 'resize');
    
    for (var i = 0; i < remove_marker.length; i++) {

        var marker1 = new google.maps.Marker
          ({
            map: map,
            position: remove_marker[i]
          });
 
          marker1.setMap(null);
    }
    
    if (!place.geometry) {
        
      return;
    }

    // If the place has a geometry, then present it on a map.
    if (place.geometry.viewport)
    {
        map.fitBounds(place.geometry.viewport);
        //console.log(place.geometry);
        var getbounds = map.getCenter(place.geometry.location);
        //alert(place_type);
        var newcenter = [];
        newcenter[0] = place.geometry.location.lat();
        newcenter[1] = place.geometry.location.lng();
        //alert("My center"+newcenter);
        
        var getcenter = new google.maps.LatLng(newcenter[0], newcenter[1]);
        //alert("GEOMETRY"+getcenter);
        
        var request = {
        location: getcenter,
        radius: '1609.34',
        types: [""+place_type+""]
        };
        
        var circle = new google.maps.Circle({
              map: map,
              strokeWeight: 0.5,
              strokeColor: '#3FAA3A',
              radius: 2000.34,    // 1 mile in metres
              fillColor: '#64F25E',
              center: getcenter
            });

        //alert("Your Center"+request);
        service = new google.maps.places.PlacesService(map);
        service.nearbySearch(request, callback);
 
        }
    else
    {
    
        var newcenter = [];
        newcenter[0] = place.geometry.location.lat();
        newcenter[1] = place.geometry.location.lng();
        //alert("My center"+newcenter);
        //alert(place_type);    
        var getcenter = new google.maps.LatLng(newcenter[0], newcenter[1]);
        //alert("Your Center"+getcenter);
        
        
        var request = {
        location: getcenter,
        radius: '1609.34',
        types: [""+place_type+""]
        };

        var circle = new google.maps.Circle({
              map: map,
              strokeWeight: 0.5,
              strokeColor: '#3FAA3A',
              radius: 2000.34,    // 1 mile in metres
              fillColor: '#64F25E',
              center: getcenter
            });

        service = new google.maps.places.PlacesService(map);
        service.nearbySearch(request, callback);
    
  
    }
    marker.setIcon(/** @type {google.maps.Icon} */({
      url: place.icon,
      size: new google.maps.Size(71, 71),
      origin: new google.maps.Point(0, 0),
      anchor: new google.maps.Point(17, 34),
      scaledSize: new google.maps.Size(35, 35)
    }));
    marker.setPosition(place.geometry.location);
    marker.setVisible(true);

    var address = '';
    if (place.address_components) {
            //alert(place.address_components[1].short_name);
            address = [
                (place.address_components[0] && place.address_components[0].short_name || ''),
                (place.address_components[1] && place.address_components[1].short_name || ''),
                (place.address_components[2] && place.address_components[2].short_name || '')
                ].join(' ');
            //alert("ADDRESS: "+address);
        
    }

    infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address);
    infowindow.open(map, marker);
 
 });
 
}
  //-----------------------------------------------------------------//



//------------------------FUNCTION CALLBACK FOR PLOTING MARKERS OF NEARBY SEARCH---------------------------------//

function callback(results, status) {
    var area_name = document.getElementById('coord0');


  if (status == google.maps.places.PlacesServiceStatus.OK) {
    //alert(status);
    
    console.log(results);
     var placelat = results[0].geometry.location.lat();
    var placelng = results[0].geometry.location.lng();
    
    var center1 = new google.maps.LatLng(placelat,placelng);
    //alert(placelat+", "+placelng);
    
    for (var i = 0; i < results.length; i++) {
      createMarker(results[i]);
            remove_marker.push(results[i].geometry.location);
      place_name.push(results[i].name);
    }
    
    map.setZoom(14);
    map.setCenter(center1);
    //alert(tubes);
    tubes = "";
    //alert(tubes);
    //alert(place_name);
    area_name.value = place_name;
    place_name = [];
    /*if (results)
    {
        for (i in results)
        {
          results[i].setMap(null);
        }
        results.length = 0;
    }*/
    //alert(place_name);
  }
  else
  {
    area_name.value = place_name;
  }
}


function createMarker(place) {
    var placelat = place.geometry.location.lat();
    var placelng = place.geometry.location.lng();
 
 
 
  var center1 = new google.maps.LatLng(placelat,placelng);
 
  infowindow = new google.maps.InfoWindow();
 
  tubes = new google.maps.Marker({
    map: map,
    position: place.geometry.location
  });
 
  tubes.setMap(map);
 
  google.maps.event.addListener(tubes, 'click', function() {
    infowindow.setContent(place.name);
    infowindow.open(map, this);
  });

 
}



function removeMarker(place) {
    var placelat = place.lat();
    var placelng = place.lng();
 
 
  alert(place);
  var center1 = new google.maps.LatLng(placelat,placelng);
 
  infowindow = new google.maps.InfoWindow();
 
  tubes = new google.maps.Marker
  ({
    map: map,
    position: place
  });
 
  tubes.setMap(null);
 
}


//------------------------FUNCTION CALLBACK FOR PLOTING MARKERS OF NEARBY SEARCH---------------------------------//


 google.maps.event.addDomListener(window, 'load', initialize);

</script>
</head>
<body>

<textarea id="coord0" width="700"></textarea><br>
<div id="selection">
Select Your Place Type
<select id="place_type">
    <option value="airport">Airpot</option>
    <option value="amusement_park">Amusement_park</option>
    <option value="aquarium">Aquarium</option>
    <option value="art_gallery">Art_gallery</option>
    <option value="atm">ATM</option>
    <option value="bakery">Bakery</option>
    <option value="bank">Bank</option>
    <option value="bar">Bar</option>
    <option value="beauty_salon">Beauty_salon</option>
    <option value="bicycle_store">Bicycle_store</option>
    <option value="book_store">Book_store</option>
    <option value="bowling_alley">Bowling_alley</option>
    <option value="bus_station">Bus_station</option>
    <option value="cafe">Cafe</option>
    <option value="car_dealer">Car_dealer</option>
    <option value="car_rental">Car_rental</option>
    <option value="car_repair">Car_repair</option>
    <option value="car_wash">Car_wash</option>
    <option value="casino">Casino</option>
    <option value="cemetery">Cemetery</option>
    <option value="church">Church</option>
    <option value="city_hall">City_hall</option>
    <option value="clothing_store">Clothing_store</option>
    <option value="convenience_store">Convenience_store</option>
    <option value="courthouse">Courthouse</option>
    <option value="dentist">Dentist</option>
    <option value="department_store">Department_store</option>
    <option value="doctor">Doctor</option>
    <option value="electrician">Electrician</option>
    <option value="electronics_store">Electronics_store</option>
    <option value="embassy">Embassy</option>
    <option value="establishment">Establishment</option>
    <option value="fire_station">Fire_station</option>
    <option value="florist">Florist</option>
    <option value="food">Food</option>
    <option value="funeral_home">Funeral_home</option>
    <option value="furniture_store">Furniture_store</option>
    <option value="gas_station">Gas_station</option>
    <option value="general_contractor">General_contractor</option>
    <option value="grocery_or_supermarket">Grocery_or_supermarket</option>
    <option value="gym">Gym</option>
    <option value="hair_care">hair_care</option>
    <option value="hardware_store">hardware_store</option>
    <option value="health">health</option>
    <option value="hindu_temple">hindu_temple</option>
    <option value="home_goods_store">home_goods_store</option>
    <option value="hospital">hospital</option>
    <option value="insurance_agency">insurance_agency</option>
    <option value="jewelry_store">jewelry_store</option>
    <option value="laundry">laundry</option>
    <option value="lawyer">lawyer</option>
    <option value="library">library</option>
    <option value="liquor_store">liquor_store</option>
    <option value="local_government_office">local_government_office</option>
    <option value="locksmith">locksmith</option>
    <option value="lodging">lodging</option>
    <option value="meal_delivery">meal_delivery</option>
    <option value="meal_takeaway">meal_takeaway</option>
    <option value="mosque">mosque</option>
    <option value="movie_rental">movie_rental</option>
    <option value="museum">museum</option>
    <option value="night_club">night_club</option>
    <option value="movie_theater">movie_theater</option>
    <option value="painter">painter</option>
    <option value="park">park</option>
    <option value="pet_store">pet_store</option>
    <option value="pharmacy">pharmacy</option>
    <option value="physiotherapist">physiotherapist</option>
    <option value="police">police</option>
    <option value="post_office">post_office</option>
    <option value="restaurant">restaurant</option>
    <option value="school">school</option>
    <option value="shopping_mall">shopping_mall</option>
    <option value="shoe_store">shoe_store</option>
    <option value="spa">spa</option>
    <option value="stadium">stadium</option>
    <option value="store">store</option>
    <option value="subway_station">subway_station</option>
    <option value="synagogue">synagogue</option>
    <option value="taxi_stand">taxi_stand</option>
    <option value="train_station">train_station</option>
    <option value="travel_agency">travel_agency</option>
    <option value="university">university</option>
    <option value="veterinary_care">veterinary_care</option>
     <option value="zoo">zoo</option>
</select>
</div><br>
<input type="text" id="country_name" >

<div id="googleMap">
    
</div>

</body>
</html>

Tuesday, 10 June 2014

Binding DataReader result to GridView control in C#


DATAREADER
DataReader is used to read the data from database and it is a read and forward only connection oriented architecture during fetch the data from database. DataReader will fetch the data very fast when compared with dataset. Generally we will use ExecuteReader object to bind data to datareader.
To bind DataReader data to GridView we need to write the code like as shown below:
Protected void BindGridview()
{
using (SqlConnection conn = new SqlConnection("Data Source=MyDatabase;Integrated Security=true;Initial Catalog=Test"))
{
con.Open();
SqlCommand cmd = new SqlCommand("Select UserName, First Name,LastName,Location FROM MyTableNm", conn);
SqlDataReader sdr = cmd.ExecuteReader();
gvUserInfo.DataSource = sdr;
gvUserInfo.DataBind();
conn.Close();
}
}

Monday, 9 June 2014

Jquery Typewriter

HTML code:

<html>
<body onload='boot();'>
  <div id='container'>
    <h1>Jquery Typewriter</h1>
    <div id='main'>
<p><a href='#' onclick='$("#typewriter").typewriter(); return false;'>Run demo</a></p>
<div id='typewriter'>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>
 </div>
 </body>
</htmkl>

Javascript Code:

 function shuffle(a) {
        var i = a.length, j;
        while (i) {
            var j = Math.floor((i--) * Math.random());
            var t = a[i];
            a[i] = a[j];
            a[j] = t;
        }
    }
 
    function randomAlphaNum() {
        var rnd = Math.floor(Math.random() * 62);
        if (rnd >= 52) return String.fromCharCode(rnd - 4);
        else if (rnd >= 26) return String.fromCharCode(rnd + 71);
        else return String.fromCharCode(rnd + 65);
    }
 
    $.fn.rot13 = function() {
        this.each(function() {
            $(this).text($(this).text().replace(/[a-z0-9]/ig, function(chr) {
                var cc = chr.charCodeAt(0);
                if (cc >= 65 && cc <= 90) cc = 65 + ((cc - 52) % 26);
                else if (cc >= 97 && cc <= 122) cc = 97 + ((cc - 84) % 26);
                else if (cc >= 48 && cc <= 57) cc = 48 + ((cc - 43) % 10);
                return String.fromCharCode(cc);
            }));
        });
        return this;
    };
 
    $.fn.scrambledWriter = function() {
        this.each(function() {
            var $ele = $(this), str = $ele.text(), progress = 0, replace = /[^\s]/g,
                random = randomAlphaNum, inc = 3;
            $ele.text('');
            var timer = setInterval(function() {
                $ele.text(str.substring(0, progress) + str.substring(progress, str.length).replace(replace, random));
                progress += inc
                if (progress >= str.length + inc) clearInterval(timer);
            }, 100);
        });
        return this;
    };
 
    $.fn.typewriter = function() {
        this.each(function() {
            var $ele = $(this), str = $ele.text(), progress = 0;
            $ele.text('');
            var timer = setInterval(function() {
                $ele.text(str.substring(0, progress++) + (progress & 1 ? '_' : ''));
                if (progress >= str.length) clearInterval(timer);
            }, 100);
        });
        return this;
    };
 
    $.fn.unscramble = function() {
        this.each(function() {
            var $ele = $(this), str = $ele.text(), replace = /[^\s]/,
                state = [], choose = [], reveal = 25, random = randomAlphaNum;
         
            for (var i = 0; i < str.length; i++) {
                if (str[i].match(replace)) {
                    state.push(random());
                    choose.push(i);
                } else {
                    state.push(str[i]);
                }
            }
         
            shuffle(choose);
            $ele.text(state.join(''));
         
            var timer = setInterval(function() {
                var i, r = reveal;
                while (r-- && choose.length) {
                    i = choose.pop();
                    state[i] = str[i];
                }
                for (i = 0; i < choose.length; i++) state[choose[i]] = random();
                $ele.text(state.join(''));
                if (choose.length == 0) clearInterval(timer);
            }, 100);
        });
        return this;

    };

Live Demo : 


http://jsfiddle.net/pankaj7418/mfM98/

Copy file from one folder to another in php

Below code is delete the file from one folder and copy in destination folder.

<?php

  $dir_path = getcwd();
   $dir = $dir_path."/folder1/";
   $dirNew =$dir_path."/folder2/";
    if (is_dir($dir)) {

        if ($dh = opendir($dir)) {

            while (($file = readdir($dh)) !== false) {

            if ($file==".") continue;
            if ($file=="..")continue;
chmod("$dir", 0777);
chmod("$dirNew", 0777);
            if (copy("$dir/$file","$dirNew/$file"))
                {
                 if(unlink("$dir/$file")){
                     echo "Delete Sucessfully";
                 }
                echo "Files Copyed Successfully";
                 
                }
                else {echo "File Not Copy";}
            }
            closedir($dh);
        }
    }

?>

Tuesday, 3 June 2014

Find curly bracket issues in php file

The below code determines the missing bracket issue in php file.

<?php
$file_path = "../www/class.php"; //privide here the name of the file
$code = file_get_contents($file_path);

$code_is_valid = preg_match('~^({ ( (?>[^{}]+) | (?1) )* })$~x', '{' . $code .'}');
if($code_is_valid == 1)
{
echo "No bracket issue found";
}
else
{
echo "Error,opening/closing bracket missing";
}
?>