Tuesday 3 January 2017

how to create Your Promo Code in php.

$characters = array(
"A","B","C","D","E","F","G","H","J","K","L","M",
"N","P","Q","R","S","T","U","V","W","X","Y","Z",
"1","2","3","4","5","6","7","8","9");
$keys = array();
while(count($keys) < 8) {
    $x = mt_rand(0, count($characters)-1);
    if(!in_array($x, $keys)) {
       $keys[] = $x;
    }
}
foreach($keys as $key){
   $random_chars .= $characters[$key];
}
echo $random_chars;

Sunday 1 January 2017

how to calculate age time formate function in php

<?php



create function : 




 function get_timeago($ptime)
{
    $estimate_time = time() - $ptime;

    if( $estimate_time < 1 )
    {
        return 'just now';
    }

    $condition = array(
                12 * 30 * 24 * 60 * 60  =>  'year',
                30 * 24 * 60 * 60       =>  'month',
                24 * 60 * 60            =>  'day',
                60 * 60                 =>  'hour',
                60                      =>  'minute',
                1                       =>  'second'
    );

    foreach( $condition as $secs => $str )
    {
        $d = $estimate_time / $secs;
       

        if( $d >= 1 )
        {
            $r = round( $d );
            return 'about ' . $r . ' ' . $str . ( $r > 1 ? 's' : '' ) . ' ago';
        }
    }
}

use function

$timeago = get_timeago(strtotime($datee['date']));

?>

Tuesday 27 December 2016

Load more button data show with ajax in php.

index.php =>

             $rowperpage = 5;
            // counting total number of posts
            $allcount_query = "SELECT count(*) as allcount FROM signup where type='teacher'";
            $allcount_result = mysql_query($allcount_query);
            $allcount_fetch = mysql_fetch_array($allcount_result);
            $allcount = $allcount_fetch['allcount'];

            // select first 5 posts
            $query = "select * from signup where type='teacher' order by id DESC limit 0,$rowperpage ";
            $result = mysql_query($query);

            while($row = mysql_fetch_array($result)){

//your code here...............you want to show .
 
            }
}
            ?>
            <h1 class="load-more button btn">Load More</h1>
            <input type="hidden" id="row" value="0">
            <input type="hidden" id="all" value="<?php echo $allcount; ?>">



.js file =>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

  <script type="text/javascript">
$(document).ready(function(){

    // Load more data
    $('.load-more').click(function(){
        var row = Number($('#row').val());
        var allcount = Number($('#all').val());
        var rowperpage = 5;
        row = row + rowperpage;

        if(row <= allcount){
            $("#row").val(row);

            $.ajax({
                url: 'loadmore.php',
                type: 'post',
                data: {row:row},
                beforeSend:function(){
                    $(".load-more").text("Loading...");
                },
                success: function(response){

                    // Setting little delay while displaying new content
                    setTimeout(function() {
                        // appending posts after last post with class="post"
                        $(".post:last").after(response).show().fadeIn("slow");

                        var rowno = row + rowperpage;

                        // checking row value is greater than allcount or not
                        if(rowno > allcount){

                            // Change the text and background
                            $('.load-more').text("No More Result");
                            $('.load-more').css("background","darkorchid");
                        }else{
                            $(".load-more").text("Load more");
                        }
                    }, 2000);


                }
            });
        }else{
            $('.load-more').text("Loading...");

            // Setting little delay while removing contents
            setTimeout(function() {

                // When row is greater than allcount then remove all class='post' element after 3 element
                $('.post:nth-child(5)').nextAll('.post').remove();

                // Reset the value of row
                $("#row").val(0);

                // Change the text and background
                $('.load-more').text("Load more");
                $('.load-more').css("background","#15a9ce");
             
            }, 2000);


        }

    });

});

  </script>


loadmore.php =>

<?php

//include database configuration file
$row = $_POST['row'];
$rowperpage = 5;

// selecting posts
$query = 'SELECT * FROM signup WHERE type="teacher" order by id DESC limit '.$row.','.$rowperpage;
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){ 

your code here after load more data show.


} ?>



Tuesday 6 December 2016

Page onload automatic click button and link in jquery.

<script>
window.onload = function(){
  document.getElementById("autopop").click();
}
</script>
</head>
<body>
<a href="#" class="link-login" id="autopop"></a>

Friday 18 November 2016

Ajax Search in php

(index.php)

<div id="content">
<input type="text" class="search" id="searchid" placeholder="Search for parent profile" />
&nbsp; &nbsp; Example : manjeet, manjeet@gmail.com, 998822<br />
<div id="result">
</div>

</div>

(js.php)

<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(function(){
$(".search").keyup(function()
{
var searchid = $(this).val();
var dataString = 'search='+ searchid;
if(searchid!='')
{
    $.ajax({
    type: "POST",
    url: "search.php",
    data: dataString,
    cache: false,
    success: function(html)
    {
    $("#result").html(html).show();
    }
    });
}return false;  
});

jQuery("#result").live("click",function(e){
    var $clicked = $(e.target);
    var $name = $clicked.find('.name').html();
    var decoded = $("<div/>").html($name).text();
    $('#searchid').val(decoded);
});
jQuery(document).live("click", function(e) {
    var $clicked = $(e.target);
    if (! $clicked.hasClass("search")){
    jQuery("#result").fadeOut();
    }
});
$('#searchid').click(function(){
    jQuery("#result").fadeIn();
});
});

</script>


(search.php)

if($_POST)
{
$q=$_POST['search'];
$sql_res=mysql_query("SELECT * FROM `signup` WHERE `first_name` LIKE '%$q%' OR `email` LIKE '%$q%' OR `mobile` LIKE '%$q%' order by id LIMIT 5");
while($row=mysql_fetch_array($sql_res))
{
$username=$row['first_name'];
$email=$row['email'];
$b_username='<strong>'.$q.'</strong>';
$b_email='<strong>'.$q.'</strong>';
$final_username = str_ireplace($q, $b_username, $username);
$final_email = str_ireplace($q, $b_email, $email);
?>
<?php
if($row['type']=='parent'){?>
<div class="show" align="left">
<div onclick="send(<?php echo $row['id']; ?>)"><img src="<?php echo SITE_URL; ?>img/zs.png" style="width:50px; height:50px; float:left; margin-right:6px;" /><span class="name"><?php echo $final_username; ?></span>&nbsp;<br/><?php echo $final_email; ?>&nbsp;<br/><?php echo $row['mobile']; ?><br/></div>
</div>
<?php }
}
}

Friday 30 September 2016

How to use php varible in javascript.

<?php
$varible = "get any string or fetch any data from database";

   ?>
       <script type="text/javascript">
   var show= "<?php echo strip_tags($varible); ?>";
  alert(show);
  </script>

How to use javascript Function in php

<a href="javascript:readmore(id)"> Read More </a>

<script type="text/javascript">
function readmore(id)
{
 if(confirm('Sure To Remove This Chat ?'))
     {
        window.location.href='?readmore='+id;
      }
}
</script>

Tuesday 13 September 2016

how to share any post on facebook in php

<?php
$data = "pppppppppppppppppppppppppppp";

?>
<html>
     

<head>
    <title>Facebook Share Button - External Website</title>
   
<style type="text/css">

body { 
background:#f5f5f5;
font: 14px/150% 'century gothic',helvetica,arial;
}

#container {
margin:5px auto;
padding:25px;
width:400px;
border:1px solid #999;
border-radius:8px; -moz-border-radius:8px; -webkit-border-radius:8px;
background:#fff;
}
</style>


</head>

<body>

<div id="container">

<p>Manjeet kashyap</p>

<div id="fb-root"></div>


<script>
 window.fbAsyncInit = function() {
FB.init({

 appId  : '964579503687504',
 status : true, // check login status
 cookie : true, // enable cookies to allow the server to access the session
 xfbml  : true  // parse XFBML
});
 };

 (function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
 }());
</script>


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

<img id = "share_button" src = "http://app.tabpress.com/fbui_share/share_button.png">

<script type="text/javascript">
$(document).ready(function(){
$('#share_button').click(function(e){

e.preventDefault();
var m = "<?php echo $data; ?>";
FB.ui(
{

method: 'feed',
name: 'HyperArts Blog',
link: 'http://hyperarts.com/blog',
picture: 'http://www.hyperarts.com/_img/TabPress-LOGO-Home.png',
caption: 'I love HyperArts tutorials',
description: m,
message: ''
});
});
});
</script>


</div>

</body>
</html>

Friday 9 September 2016

how to check email valid on server in php.

$email = "john@gmail.com";

if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
  echo("$email is a valid email address");
} else {
  echo("$email is not a valid email address");
}

Tuesday 6 September 2016

how to call page content in template file in wordpress.

<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>