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 '',
  PRIMARY KEY  (id)
);


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">
<html>
  <head>
    <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="http://maps.google.com/maps?file=api&v=2&key=YOURKEYHERE" type="text/javascript">
</script>
<body>
<p><strong>locations in India</strong></p>
<div id="map" style="width: 800px; height: 600px"></div>

<script type="text/javascript">
//<![CDATA[
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";
    try{
        String driver = "com.mysql.jdbc.Driver";
        Class.forName(driver).newInstance();
        Connection conn;
        conn = DriverManager.getConnection(url, "root","");
        Statement s = conn.createStatement ();
        s.executeQuery ("SELECT *from latandlon");
        ResultSet rs = s.getResultSet ();
        int count = 0;
        while (rs.next ()) {
            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");
            out.print("map.addOverlay(marker);\n");
            out.print("\n");
        }
        rs.close ();
        s.close ();
    }
    catch(Exception ee){
        System.out.println(ee.toString());  
    }
%>
//]]>
</script>
</body>
</html>

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






Exact string comparison in C#

PROBLEM:
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

SOLUTION:
 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.";
                return;
} else {
     MessageBox.Show("Correct User Name.");
}




Read excel file in PHP

Problem:

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

Solution:

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

Example:

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

$worksheet=$objPHPExcel->getActiveSheet();
$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


Problem:

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.

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.

Example:

<?php
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);
            $zp->close();
            $xml = DOMDocument::loadXML($dt, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING);
            return strip_tags($xml->saveXML());
        }
        $zp->close();
    }
    return "";
}

$docx_txt=showDocxToText("file.docx");
// now store $docx_txt content to database
?>

Get Current Page Name in PHP


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

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

mail using PHPMailer

PROBLEM:
How to send using PHPMailer

SOLUTION:

PHPMailer is the good option to send email in PHP. To use PHPMailer first download it from
https://github.com/PHPMailer/PHPMailer

extract and paste entire folder. paste below code:

<?php
require_once('phpMailer/class.phpmailer.php');
public function sendEMail($tto, $fFrom, $sSubject, $bBody) {
$html_message = $bBody;
$mail = new PHPMailer();
                $mail->Host = 'mail.site.com';// 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!";
$mail->MsgHTML($html_message);
$mail->AddAddress($tto);
$mailAns = $mail->Send();
return $mailAns;
}
sendEMail("toemail", "fromemail", "subject", "email msg body")
?>

latitude and longitude by zip in php

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

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

$pin="208017";
$full_url = "http://maps.googleapis.com/maps/api/geocode/json?address=".$pin."&sensor=false";
$details=file_get_contents($full_url);
$rs = json_decode($details,true);
$lat=$rs['results'][0]['geometry']['location']['lat'];
$lng=$rs['results'][0]['geometry']['location']['lng'];
echo  "Latitude :" .$lat;
echo '<br>';
echo "Longitude :" .$lng;

Replace in mysql

PROBLEM:

How to Replace in mysql?

SOLUTION:
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

PROBLEM:
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?

SOLUTION:
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 :
"max_allowed_packet=500M"

Configure codeigniter in wamp 2.5

PROBLEM:
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 ?

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

"$suppress_localhost=false"

Show sql query in Codeigniter

Problem:

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?

Solution:
you can use this statement after execution sql query

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

Example:

$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

Problem:

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?

Solution:

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 

Example:

IN CONTROLLER :
<?php
passed $statename_list data records from mysql table by controller:
$statename_list=$this->main_model->get_statenames();
$this->load->view('main_include/6_main_content_view',$statename_list);
?>

IN VIEW :
<?php
$this->load->database();
 foreach ($statename_list->result() as $row_state) {
 echo $row_state->statename;
 //$matter_id=$row_state->matter_id;
 }
?>

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:

$statename_list=$this->main_model->get_statenames();
$data['statename_list']=$statename_list;

and pass it in view as:
$this->load->view('main_include/6_main_content_view',$data);

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

get selected text of select from jquery

Problem:
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.

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



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

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

replace all space in javascript

Problem:

How to replace all space in javascript?

Solution:

You will use "replace" method to replace in javascript

Example:


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

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

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]