Tuesday 4 October 2016

convert column name into lowercase in mysql and php

Helllo

convert column name into lowercase in mysql and php

some time we want all table column name in lower case then we can change to manually but here
example you can paste this query after run query. you can change you column name in to lower case


convert column name into lowercase in mysql and php example start.

<?php
$c1 = mysql_connect("localhost","root","");// Connection




$db1 = mysql_select_db("INFORMATION_SCHEMA");



$get_column = mysql_query("SELECT * FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA`='data_base_name' AND `TABLE_NAME`='table_name'");

while($row = mysql_fetch_assoc($get_column)){


$old_name = $row['COLUMN_NAME'];
$new_name = strtolower($row['COLUMN_NAME']);
$datatype= $row['DATA_TYPE'];
$size = $row['CHARACTER_MAXIMUM_LENGTH'];



if($row['DATA_TYPE'] !="varchar" && $row['DATA_TYPE'] !="text"){
$query =  "ALTER TABLE mstusers CHANGE $old_name $new_name $datatype".";<br/>";
}else{

$query =  "ALTER TABLE mstusers CHANGE $old_name $new_name $datatype ($size)".";<br/>";
}
echo $query;


}

// Query paste in your  phpmyadmin



?>

Please setup below code replace table_name with you table name and database_name replace with you
database name. also setup up your database connection.

After check all query for convert column name into lowercase in mysql and php.

i think it work for you.

convert column name into lowercase in mysql and php

Monday 3 October 2016

ajax image upload with form data in jquery and php

ajax image upload with form data in jquery and php


Hello Here example how to image upload using ajax using php.

and also know how to another value in ajax request.

ajax image upload with form data in jquery and php. please check below example to pass ajax data pass in jquery.

ajax image upload with form data in jquery and php

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script type="application/javascript">
$(document).ready(function (e) {
    $('#imageUploadForm').on('submit',(function(e) {
        e.preventDefault();

        var formData = new FormData();
var text = $('input[type=text]').val();

formData.append('image', $('input[type=file]')[0].files[0]);
formData.append('test', text);


        $.ajax({
            type:'POST',
            url: $(this).attr('action'),
            data:formData,
            cache:false,
            contentType: false,
            processData: false,
            success:function(data){
                console.log("success");
                console.log(data);
$('#imageUploadForm')[0].reset();
            },
            error: function(data){
                console.log("error");
                console.log(data);
            }
        });
    }));

    $("#ImageBrowse").on("change", function() {
        $("#imageUploadForm").submit();
    });
});
</script>
<form name="photo" id="imageUploadForm" enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"];?>" method="post">
    <input type="file" id="ImageBrowse"  name="image" size="30"/>
     <input type="text" id="text"  value="nice man" name="text" size="30"/>
    <input type="submit" name="upload" value="Upload" />
   
</form>
<?php
if(isset($_FILES['image'])){
if(!is_dir('ajax_image')){
mkdir('ajax_image');
}
echo "GET TEXT BOX VALUE = ".$_POST['test'];
$path = $_FILES['image']['tmp_name'];
$new = "ajax_image/".uniqid().$_FILES['image']['name'];
move_uploaded_file($path,$new);
}
 ?>

ajax image upload with form data in jquery and php

Saturday 17 September 2016

JQuery Autocomplete example in Codeingniter

JQuery Autocomplete example in Codeingniter

Hello here simple example to autocomplete setup in codegniter

sample code to use it.

 <input type="text"  class="form-control skills"  name="name" placeholder="Type Name"  />
 <style>
.fixedHeight {
   
    font-size:10px;
    max-height: 150px;
    margin-bottom: 10px;
    overflow-x: auto;
    overflow-y: auto;
}


</style>
 <script type="application/javascript">

 $(function() {
$( ".skills" ).autocomplete({
source: '<?php echo base_url() ?>'+'/controler_name/function_name',
   
})
  

$( ".skills" ).autocomplete("widget").addClass("fixedHeight");
});

 </script>

 <?php
 //in controller
 // function name(create you own function name and setup)
 public function userautocompltedservices(){
$term =  $this->input->get('term',true);



$query = $this->db->select('servicename')->from('serviceslist')
       ->where("servicename LIKE '%$term%'")->get();
  
   $datas = $query->result_array();
  foreach($datas as $dat){
 
  $data[] = $dat['servicename'];
}
 
  
   echo json_encode($data);
}

 ?>

 JQuery Autocomplete example in Codeingniter fully example

 

send email using SMTP config in codeigniter 3

Hello

send email using SMTP config in codeigniter 3

here example how to setup SMTP in codeigniter 3

first download the php mailler

put after extract foleder phpmailer folder move to codeigniter in application\libraries

after create libraries in  application\libraries create file my_phpmailer.php

here the code of my_phpmailer.php file

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class My_PHPMailer {
    public function My_PHPMailer() {
        require_once('PHPMailer/PHPMailerAutoload.php');
    }
   
   


}

3) Go To application\helpers create file  sendemails_helper.php

her code of header 


if(!function_exists('send_emails'))
    {
             function send_emails($emails,$body,$subject){
                    $mail = new PHPMailer;
                   
                    $mail->isSMTP();      
                    $mail->Host = 'smtp.mail.yahoo.com';  //                               // Set mailer to use SMTP
                   
                    $mail->SMTPAuth = true;                               // Enable SMTP authentication
                    $mail->Username = 'yahoomail';                 // SMTP username
                    $mail->Password = 'yahoopassword';                           // SMTP password
                    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
                    $mail->Port = 465;                                    // TCP port to connect to
                   
                    $mail->setFrom('jhparmar87@yahoo.com', 'title name');
                   
                   
                    $mail->addAddress($emails, 'user');
               
                   
                    $mail->isHTML(true);                                  // Set email format to HTML
                   
                    $mail->Subject = $subject;
                    $mail->MsgHTML($body);
                   
                    $mail->send();
           
             }
    }

after go to application\config open the file autoload.php

$autoload['libraries'] = array('database','session','My_PHPMailer');// here add you library My_PHPMailer

$autoload['helper'] = array('url', 'file','form','sendemails');// here add you helper file  sendemails

after when controler you want to send mail from smtp setup this helper function

    send_emails("test@yahoo.com","body content","subject"); 

here fully exmple of send email using SMTP config in codeigniter 3 please check it now

Friday 16 September 2016

How to fetch title of an product name from a database and send it to the header template in CodeIgniter

How to fetch title of an product name from a database and send it to the header template in CodeIgniter

Hello

If you want product name title in header title then follow this in incrustation.

In Model

function get_prductname($pid)
{
    $query = $this->db->query("SELECT * FROM table_name WHERE pid= '$pid' ");
   
    $count = count($result); # New

    return  $result = $query->row();
}
 
In Controller
 
public function prodcudetail($pid)
{
    $result = $this->Listing_model->get_prductname($pid); # Changed

    $data["page_title"] = $result[0]['field_name']; # Changed

        $this->load->view('includes/header',$data); # Changed
        $this->load->view('listings/listing_card',$data);
        $this->load->view('includes/footer');

}  
 
In View
 
php echo (!empty($page_title->productname)) ? $page_title->productname : ''; ?> # Changed   
 
This example of how setup  product name from a database and send it to the header template in CodeIgniter

How to manange two different codeigniter session value in localhost?

Hello

Here issue If we Install Two codeigniter in localhost then some time session value config with another codeigniter .

for example

I Have to develope two different different site in login query i am create user_login session for two website same. one site login  it's effect to another site

if one of site logout then second website automatically logout.

for this issue we have to manage config file.

all website set in config file this

$config['sess_cookie_name'] = 'you own name for the session';
 
 


Monday 18 July 2016

get time between two different locations using latitude and longitude in php

Get time between two different locations using latitude and longitude in php

<?php

$url ="https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=16.538048,80.613266&destinations=23.0225,72.5714";



$ch = curl_init();
// Disable SSL verification

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);

$result_array=json_decode($result);

//print_r();
echo "<pre>";
print_r($result_array->rows[0]->elements[0]->duration->text);

Wednesday 29 June 2016

Displaying a flash message after redirect in Codeigniter

Displaying a flash message after redirect in Codeigniter


In Your Controller set this
<?php

public function change_password(){







if($this->input->post('submit')){
$change = $this->common_register->change_password();

if($change == true){
$messge = array('message' => 'Password chnage successfully','class' => 'alert alert-success fade in');
$this->session->set_flashdata('item', $messge);
}else{
$messge = array('message' => 'Wrong password enter','class' => 'alert alert-danger fade in');
$this->session->set_flashdata('item',$messge );
}
$this->session->keep_flashdata('item',$messge);



redirect('controllername/methodname','refresh');
}

?>

In Your View File Set this
<script type="application/javascript">
/** After windod Load */
$(window).bind("load", function() {
  window.setTimeout(function() {
    $(".alert").fadeTo(500, 0).slideUp(500, function(){
        $(this).remove();
    });
}, 4000);
});
</script>

<?php

if($this->session->flashdata('item')) {
$message = $this->session->flashdata('item');
?>
<div class="<?php echo $message['class'] ?>"><?php echo $message['message']; ?>

</div>
<?php
}

?>

Sunday 19 June 2016

adding multiple markers to google maps using javascript and php

Adding multiple markers to google maps using javascript and php

adding multiple markers to google maps using javascript and php
Please Check Below File

Create map3.php File same as here

$conn = mysql_connect("localhost","root","");

mysql_select_db('yourdatabase');

function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}

$query = mysql_query("select * from yourtable");



//header("Content-type: text/html");

/* Get lat and Lan using table query */
$i=0;

while($row = mysql_fetch_assoc($query)){
   

$reposnse['markers'][$i]['lat']= $row['lat'];
$reposnse['markers'][$i]['lag']= $row['lag'];


$i++;
}

echo json_encode($reposnse);
?>

After create map2.php same as here

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>

    <script type="application/javascript">

  

     

     $(document).ready(function(e) {
       


$.ajax({
url:"map3.php",
dataType: 'json',
success: function(result){
var html = '<markers>';


for (var prop in result['markers']) {

var value = result['markers'][prop];
//alert(value.lat);
html += '<marker ';
html += 'lat="';
html += value.lat+'"';
html += 'lng="';
html += value.lag+'"';
html += '/>';
}
html += '</markers>';
$('#test').html(html);

function initialize() {
        var map = new google.maps.Map(document.getElementById('map'), {
            zoom: 6,
            center: new google.maps.LatLng(15.317277,75.71389),
            mapTypeId: google.maps.MapTypeId.ROADMAP
        });

var infowindow = new google.maps.InfoWindow();

        var marker;

        var location = {};


var markers = document.getElementsByTagName("marker");


        for (var i = 0; i < markers.length; i++) {

//alert(markers[i].getAttribute("lat"));
            location = {
                name : 'test'+i,
                address : 'baglore',
                city : 'bangalore',
                state : 'Karnataka',
                zip : '560017',
                pointlat : parseFloat(markers[i].getAttribute("lat")),
                pointlng : parseFloat(markers[i].getAttribute("lng"))  
            };

            console.log(location);

            marker = new google.maps.Marker({
                position: new google.maps.LatLng(location.pointlat, location.pointlng),
                map: map
            });

            google.maps.event.addListener(marker, 'click', (function(marker,location) {
                return function() {
                    infowindow.setContent(location.name);
                    infowindow.open(map, marker);
                };
            })(marker, location));
        }
  }

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

},
});

    });
 
    </script>
</head>
<body>
    <div id="test">
    </div>

    <div id="map" style="width: 500px; height: 400px;"></div>
</body>
</html>

adding multiple markers to google maps using javascript and php

Friday 27 May 2016

Get geo location with latitude and lagitaure and address in javascript using browser

Get geo location with latitude and lagitaure and address in javascript using browser

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="application/javascript">

function GetAddress(lat,long) {
            var lat = parseFloat(lat);
            var lng = parseFloat(long);
            var latlng = new google.maps.LatLng(lat, lng);
            var geocoder = geocoder = new google.maps.Geocoder();
            geocoder.geocode({ 'latLng': latlng }, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    if (results[1]) {
                        alert("Location: " + results[1].formatted_address);
                    }
                }
            });
        }
function geoFindMe() {
  var output = document.getElementById("out");

  if (!navigator.geolocation){
    output.innerHTML = "<p>Geolocation is not supported by your browser</p>";
    return;
  }

  function success(position) {
 
  console.log(position);
    var latitude  = position.coords.latitude;
    var longitude = position.coords.longitude;

    output.innerHTML = '<p>Latitude is ' + latitude + '° <br>Longitude is ' + longitude + '°</p>';

   // var img = new Image();
    //img.src = "https://maps.googleapis.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&zoom=13&size=300x300&sensor=false";

//var test = "http://maps.googleapis.com/maps/api/geocode/json?latlng=44.4647452,7.3553838&sensor=true";
//console.log(test);

GetAddress(latitude,longitude);

    //output.appendChild(img);
  };

  function error() {
    output.innerHTML = "Unable to retrieve your location";
  };

  output.innerHTML = "<p>Locating…</p>";

  navigator.geolocation.getCurrentPosition(success, error);
}
</script>

<p><button onclick="geoFindMe()">Show my location</button></p>
<div id="out"></div>