Ads Inside Post

Search in This Blog

How to show place in Google map

How to show place in Google map

1) Create a table "latandlon" in Mysql/Oracle/Sqlserver/DB2 in which you feel easy.

CREATE TABLE latandlon (
  id int(11) NOT NULL auto_increment,
  lat decimal(10,6) NOT NULL default '0.000000',
  lon decimal(10,6) NOT NULL default '0.000000',
  address varchar(255) NOT NULL default '',

2) feed the listed below data.
id,     lat,            lon,            address
1    23.402800    78.454100    Madhya Pradesh
2    26.280000    80.210000    Kanpur
3    31.122027    77.111664    Himanchal Pradesh
4    22.533000    88.367000    Kolkata
5    28.350000    77.120000    Delhi
6    17.230000    78.290000    Hyderabad

3) put youe google map key in the index.jsp.

 <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
// How to show place in google map
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <base href="<%=basePath%>">
   <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">  
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <link rel="stylesheet" type="text/css" href="styles.css">
<script src="" type="text/javascript">
<p><strong>locations in India</strong></p>
<div id="map" style="width: 800px; height: 600px"></div>

<script type="text/javascript">
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());
map.setCenter(new GLatLng(23.402800, 78.454100), 5, G_NORMAL_MAP);
function createMarker(point, number)
var marker = new GMarker(point);
var html = number;
GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
return marker;
    String userName = "root";
    String password = "";
    String url = "jdbc:mysql://localhost:3306/test";
        String driver = "com.mysql.jdbc.Driver";
        Connection conn;
        conn = DriverManager.getConnection(url, "root","");
        Statement s = conn.createStatement ();
        s.executeQuery ("SELECT *from latandlon");
        ResultSet rs = s.getResultSet ();
        int count = 0;
        while ( ()) {
            String lat = rs.getString ("lat");
            String lon = rs.getString ("lon");
            String address=rs.getString ("address");
            out.print("var point = new GLatLng("+lat+","+lon+");\n");
            out.print("var marker = createMarker(point, '"+address+"');\n");
        rs.close ();
        s.close ();
    catch(Exception ee){

4) change the database connection string in the index.jsp page, coz I have used MySql.

Exact string comparison in C#

Exact string comparison in C# ,Case sensitive login in C#. Suppose you are storing login in database table as "Admin" and on the webpage or winform you are trying to compare it as "admin" then it is pass.But if you want to compare it as exact "Admin" the follow below steps:
Store "admin" in database table. So "admin" and "Admin" is not same

 String tmpLogin="Admin";
// Select user_login from user_info where user_login='Admin
String ret_login=Util.getLogin(tmpLogin);
// It will return "admin" so "admin" and "Admin" is not same. so it should false.
if (String.Equals(tmpLogin, ret_login, StringComparison.Ordinal)==false) {
                MessageBox.Show("Incorrect User Name.");
                label7.Text = "Incorrect UserName.";
} else {
     MessageBox.Show("Correct User Name.");

Read excel file in PHP


How to read Excel 2003 or 2007 or 2010 format microsoft excel file in PHP


Use  PHPExcel library to read Excel 2003 or 2007 or 2010 format microsoft excel file in PHP.
Download it from it's website


Below the code that will read excel file.
require_once './PHPExcel/IOFactory.php';
$objReader = PHPExcel_IOFactory::createReader('excel2007');//excel2007 or Excel5
$objPHPExcel = $objReader->load("Test.xlsx");

$lastRow = $worksheet->getHighestRow();
$lastCol = $worksheet->getHighestColumn();

for ($row = 2; $row <= $lastRow; $row++){
   echo $worksheet->getCell("A".$row)->getValue()."======";
   echo $worksheet->getCell("B".$row)->getValue()."<br/>"; 
 /// so on.......

Extract text from docx in php


Sometime you need to store Microsoft word 2007 file's content to Database, for this you will open docx file;copy it's content and paste in webpage and click submit button then after data will store in database. it is the solution but it is not a good smart solution.


The good smart solution is that you select your docx file by browse button then your docx file will upload in server and it's content will store in Database.


function showDocxToText($file_name) {
    return readDocxToXML($file_name, "word/document.xml");
function readDocxToXML($file_name, $data_file) {
    $zp = new ZipArchive;
    if (true === $zp->open($file_name)) {
        if (($id = $zp->locateName($data_file)) !== false) {
            $dt = $zp->getFromIndex($id);
            return strip_tags($xml->saveXML());
    return "";

// now store $docx_txt content to database

Get Current Page Name in PHP

During coding in php, some time you need to Get Current Page Name in PHP. So How to Get Current Page Name in PHP?

Create a file "b.php" and save below content and open in browser. you will see "b.php" as page name.
function getScript() {
$file = $_SERVER["SCRIPT_NAME"];
$break = explode('/', $file);
$pfile = $break[count($break) - 1];
return $pfile;
echo getScript();

mail using PHPMailer

How to send using PHPMailer


PHPMailer is the good option to send email in PHP. To use PHPMailer first download it from

extract and paste entire folder. paste below code:

public function sendEMail($tto, $fFrom, $sSubject, $bBody) {
$html_message = $bBody;
$mail = new PHPMailer();
                $mail->Host = '';// set here your mail server
                // set user and pass of your email if authentication required.
                $mail->Username     = 'user';
                $mail->Password     = 'pass';
$mail->From = $fFrom;
$mail->FromName = "Test".' '."Mail"; //name
$mail->Subject = $sSubject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mailAns = $mail->Send();
return $mailAns;
sendEMail("toemail", "fromemail", "subject", "email msg body")

latitude and longitude by zip in php

How to get latitude and longitude by zip/pin in php

Here I am demonstrating to you that how can you get latitude and longitude by zip code or pin code in php.

$full_url = "".$pin."&sensor=false";
$rs = json_decode($details,true);
echo  "Latitude :" .$lat;
echo '<br>';
echo "Longitude :" .$lng;

Replace in mysql


How to Replace in mysql?

If you have a table in my sql database which having '('    ')'   or  any other character and you want to replace it then use as:

UPDATE tble_nm  SET taluk = REPLACE(taluk, '(', '')  WHERE taluk LIKE '%)%'

Error while import sql file in sqlyog

Sometime when you import sql file then you may surprise that error show any time.The sqlyog is the good tool to import or export mysql database, You may get error while import sql file in sqlyog. So how to tackle it?

This is because your insert statement is too big to execute. to solve these problem follow listed below statement:

open "my.ini" or "my.cnf" file in the mysql folder
and change this statement as :

Configure codeigniter in wamp 2.5

If you are a PHP Developer the WAMP is a good environment. You can do the things easily with WAMP.. You can download WAMP from it's website. Recently WAMP have made many changes, in past WAMP version you simply web ste in the "www" folder and eailsy open the site. For example:
While working on codeigniter with wamp server you just past the codeigniter project directory to the wamp server "D:\wamp\www" folder. but if you have the wamp server 2.5 then your project will not work. means wrong path will shown in the browser .
But recent version of WAMp have made many changes so your site will not open. So what waht made to open website with recent WAMP? in the other words How to configure PHP website or codeigniter in wamp 2.5 ?

open "index.php" file which under "www" folder
and find the statement "$suppress_localhost=true"
and change it as below:


Show sql query in Codeigniter


While working in Codeigniter framework and execution some sql query. but the sql query result is not coming as you want. In this case there are something wrong with your sql queries. Then what you will do? the answer is that you will see the what exact sql query you are executing in Codeigniter.
So how can you show or see sql query in Codeigniter?

you can use this statement after execution sql query

you can use $this->db->last_query();  statement as below:


$sql = "SELECT district_id FROM district_names where districtname= ?";
$rsMatter=$this->db->query($sql, array($districtname));
echo $this->db->last_query();

Pass sql result in codeigniter view


PHP Codeigniter framework is a good MVC framework for PHP developer. While passwing result to it's view you may face the sql result problem. The problem is that you can not see sql result in the "View". You can face the belwo error:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: statename_list
( ! ) Fatal error: Call to a member function result() on a non-object in.
So what is the proper method to pass sql result to Codeigniter view?


You always pass array variable in the view to overcome this problem. Here I am showing the proper way that how you pass sql result to view 


passed $statename_list data records from mysql table by controller:

 foreach ($statename_list->result() as $row_state) {
 echo $row_state->statename;

By using above statements you will get the listed below error:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: statename_list
( ! ) Fatal error: Call to a member function result() on a non-object in.

PROPER SOLUTION: In controller use as:


and pass it in view as:

and use it as in view:
    <?php foreach ($statename_list->result() as $row_state) {
 $statename= $row_state->statename;

get selected text of select from jquery

How to get selected text of select from jquery?

While working in web programming sometime you need to get text from select box or combobox along with it's value.

You will use .val() method to get value and use .text() method to get text from select box or combo box in jquery.

Use listed below code:
To get value:
var myval=$("#myselect").val();

To get Text:
var mytxt=$("#myselect :selected").text();

replace all space in javascript


How to replace all space in javascript?


You will use "replace" method to replace in javascript


replace all spaces with "_" sign
statename=statename.replace(/ /g, "_");

replace all occurance in javascript
replace all spaces with "abc" sign wirh "_"

statename=statename.replace(/abc/g, "_");

Remove index.php in Codeigniter

Remove index.php from url in Codeigniter

Just copy these listed below 4 line of code ".htaccess" file in the root directory of codeigniter framework. if you have not then create it. After this restart your Server and check it.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]