31 August 2019

How to use time and date function in php with indian timezone?

Use time and date function in php with indian timezone



<?php

if(function_exists('date_default_timezone_set')) {
    date_default_timezone_set("Asia/Kolkata");
}

// then use the date functions, not the other way around
$date = date("d/m/Y");
$date1 =  date("H:i a");

echo $date . '<br/>';
echo $date1;

?>

27 August 2019

How to assign variables in php with for loop?

assign variables in php with for loop
for($i = 0; $i <= 7; $i++) {
     $name = "variable{$i}";
     $$name = "foo";
}
or
for($i = 0; $i <= 7; $i++) {
     ${"variable$i"} = "foo";
}
or
${"jassi"} .= $_POST['skip'.$daynum];

23 August 2019

How to insert time and date in database when user login on site(login tracking)?

login tracking


 if(function_exists('date_default_timezone_set')) {
date_default_timezone_set("Asia/Kolkata");
}

$date = date("d/m/Y");
$time =  date("H:i a");
global $wpdb;
$table_name = $wpdb->prefix . "logintime";
$wpdb->insert($table_name, array('start_time' => $date, 'login_date' => $time) );

21 August 2019

How to get(search) record in table with ajax via dropdown?


get(search) record in table with ajax via dropdown
Use in main file which you will create 


<script src="<?php echo plugin_dir_url(__FILE__);?>/js/jquery.min.js"></script>
<script>



jQuery(document).ready(function($){
$(".selectcustomer").change(function(){
var name = $(".selectcustomer").val();

/* alert(name); */
var data = {
'action' : 'showdata',
'custname' : name,
};
var ajaxurl = $(".ajaxurl").val();
jQuery.post(ajaxurl, data, function(response) {

console.log(response);
$(".customer-info").html(response);

});
});
});
</script>




<body>
<div class="wrapper">
<div class="wrap">
<form action="" method="post">
<div class="col-3">
<label>Customer Name</label>
<select class="selectcustomer" name="custname">
<option>Select Name</option>
<?php
global $wpdb;

$result = $wpdb->get_results ( "SELECT * FROM wp_jaspreetsingh" );
foreach ( $result as $printr ) 
{
echo"<option>$printr->person_name</option>";

}
?>
</select>
</div>
<div class="customer-info">
<div class="col-3">
<label>Customer Address</label>
<input type="text" name="customeraddress" placeholder="Customer Address" value="">
</div>
<div class="col-3">
<label>Contact Person</label>
<input type="text" name="contactperson" placeholder="Contact Person" >
</div>
<div class="col-3">
<label>Customer Email</label>
<input type="Email" name="email" placeholder="Email" value="">
</div>
<div class="col-3">
<label>Phone</label>
<input type="number" name="phone" placeholder="Phone" value="" >
</div>
</div>

</form>
</div>
</div>
<body>




         Use in function.php file which is located in theme folder.

function showdata(){
$name=$_POST['custname'];
   



        global $wpdb;
        $result = $wpdb->get_results ( "SELECT * FROM wp_jaspreetsingh where person_name='$name' " );
        foreach ( $result as $printr )   {
         
            }
      ?>

<div class="customer-info">
<div class="col-3">
<label>Customer Address</label>
<input type="text" name="customeraddress" placeholder="Customer Address" value="<?Php echo $printr->address; ?>">
</div>
<div class="col-3">
<label>Contact Person</label>
<input type="text" name="contactperson" placeholder="Contact Person" >
</div>
<div class="col-3">
<label>Customer Email</label>
<input type="Email" name="email" placeholder="Email" value="<?Php echo $printr->email; ?>">
</div>
<div class="col-3">
<label>Phone</label>
<input type="number" name="phone" placeholder="Phone" value="<?Php echo $printr->phone; ?>" >
</div>
</div>


<?php
die();

}
add_action('wp_ajax_showdata','showdata');
add_action('wp_ajax_nopriv_showdata','showdata');


How to use properly ajax in wordpress ?

                          use ajax in wordpress 

            Use in main.php file which you will create

<html>
<head>
<script src="<?php echo plugin_dir_url(__FILE__);?>/js/jquery.min.js"></script>
<script>
jQuery(document).ready(function($){
$(".select").change(function(){
var name = $(".select").val();

alert(name);
var data = {
'action' : 'showdata',
'name' : name,
};
var ajaxurl = $(".ajaxurl").val();
jQuery.post(ajaxurl, data, function(response) {

console.log(response);
$(".result").val(response);

});
});
});

</script>

<style>
.wrap{

width:80%;
margin:auto;

}

</style>
<head>
<body>
<div class="wrap">
<select class="select" >
<option value="jaspreet">jaspreet</option>
<option value="Developer">Developer</option>
<option value="Hello">Hello</option>
</select>
<div class="demo"></div>
<input type="hidden" class="ajaxurl" value="<?php echo admin_url('admin-ajax.php');?>">
<input type="text" class="result">
</div>
</body>
</html>




Use in function.php file which is located in --------->>>>>>>>>> C:\wamp64\www\home\wp-content\themes\twentynineteen





function showdata(){
$name=$_POST['name'];
echo "hello"." ".$name;
die();
}
add_action('wp_ajax_showdata','showdata');
add_action('wp_ajax_nopriv_showdata','showdata');

19 August 2019

How to add options in select html tag(Drowdown) from database in wordpress?

add options in select html tag(Drowdown) from database in wordpress


<label>Customer Name</label>
<select>
<?php
global $wpdb;

$result = $wpdb->get_results ( "SELECT * FROM wp_jaspreetsingh " );
foreach ( $result as $print ) 
{
echo"<option>$print->person_name</option>";
}
?>
</select>

How to create options is select html tag(drpopdown) in php?

create options is select html tag(drpopdown) in php


<select>
<?php

for($i=1;$i<=10;$i++){
 echo"<option>navi</option>";
}
?></select>

How to fetch instagram posts data?

Fetch Instagram posts data by pasting this code in browser console. (() => { /* ====================================================...