Top Questions

  • 2.9 Years

    • Category : Jquery
    • Location : Chandigarh
    • Posted On : Sep 20, 2017

    Display countdown timer using jQuery.

    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-countdown/2.0.2/jquery.countdown.min.js" ></script>
    
    /*html*/
    
    <span data-countdown="2017-09-25 12:10:01" ></span> // end date add here
    
    
    /*Jquery*/
    
    setTimeout(function(){
                    initCountDown()
    }, 300);            
    function initCountDown(){
        $('[data-countdown]').each(function() {
            var $this = $(this), finalDate = $(this).data('countdown');
            $this.countdown(finalDate, function(event) {
                $this.html(event.strftime('%D days %H:%M:%S'));
            });
        });
    }  
     
  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Dec 23, 2015
    <form action="" method="post" enctype="multipart/form-data" class="upload_bus"> 
    div class="btn-group col-lg-3 col-md-3 col-sm-6 col-xs-12 rightgp-btns">
      <input class="create-doc" id="upbuss"  type="file" name="upbus" >
    </div>
    </form>
    <center><div id="loader-icon" style="display:none;"><img src="images/loader-time.gif" height="100px" width="100px" /></div></center>
    <script>
    $('input#upbill').change(function(){
    $('form.upload_b').submit();
    })
    $('form.upload_b').submit(function(e){
      var formData = new FormData(this);
      $('#loader-icon').show();
    $.ajax({
    url: "upload_file.php",            
    type: "POST",
    data:  formData,
    mimeType:"multipart/form-data",
    contentType: false,
    cache: false,
    processData:false,
    success: function(data)
    {
      $('#loader-icon').hide();
       window.location.href="example.php";
    }
    });
    return false;
    });
    </script>

     

  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Jan 5, 2016
    $num_rec_per_page=4;
        if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; }; 
        $start_from = ($page-1) * $num_rec_per_page; 
    $q="select * from tablename LIMIT $start_from, $num_rec_per_page";
    $res=mysql_query($q);
    while($r=mysql_fetch_array($res))
    {
    //Enter Your code
    }
      <ul class="pagination">
            <?php 
             $sql = "SELECT * FROM `tablename`"; 
               $rs_result = mysql_query($sql); //run the query
               $total_records = mysql_num_rows($rs_result);  //count number of records
               $total_pages = ceil($total_records / $num_rec_per_page); 
             echo "<li><a href='&page=1'>".'&laquo;'."</a></li> "; // Goto 1st page  
            for ($i=1; $i<=$total_pages; $i++) { 
              echo "<li><a href='&page=".$i."'>".$i."</a></li> "; 
          }; 
             echo  "<li><a href='&page=$total_pages'>".'&raquo;'."</a></li> "; // Goto last page
    ?>
    </ul>
    
  • 5.11 Years

    • Category : Php
    • Location : Mohali
    • Posted On : Jul 2, 2016

    When you’re using a sophisticated design, CSS files can quickly become very long, and takes time to load. I have compiled interresting ways of compressing CSS files by using PHP.

    (1.)
    <link rel="stylesheet" type="text/css" media="screen" href="/style.css.php"/>
    Once you successfully rename your css files, edit it and add the following code at the beginning of the file:
    <?php if(extension_loaded('zlib')){ob_start('ob_gzhandler');} header("Content-type: text/css"); ?>
     

    2 Answers

    View More
  • 5.11 Years

    • Category : Php
    • Location : Mohali
    • Posted On : Aug 17, 2017

    MailChimp REST Api V3 exposes methods that allows you to add, change subscribed to unsubscribed, delete list member and get all member list of a specific MailChimp list.

    The following code snippet help you to add a new subscriber to MailChimp List.
    <?php
    $api_key = 'API_KEY';
    $list_id = 'LIST_ID';
    
    $dataCenter = substr($api_key,strpos($api_key,'-') + 1);
    $url = 'https://'.$dataCenter.'.api.mailchimp.com/3.0/lists/'.$list_id.'/members';
       $pfb_data = array(
        'email_address' => "YOUR_EMAIL_ID",
        'status'        => 'subscribed',
        'merge_fields'  => array(
          'FNAME'       => "YOUR_FIRST_NAME",
          'LNAME'       => "YOUR_LAST_NAME"
        ),
      );
    
    // connect and get results
    $result = json_decode( dorcode_mailchimp_curl_connect( $url, 'POST',$api_key, $pfb_data ) );
    
    if( $result->status == 400){
    	// error
       echo "already subscriber.";
    } elseif( $result->status == 'subscribed') {
    	// success
    	echo "subscribered";
    }
    ?>
    MailChimp change subscribed to unsubscribed.
    <?php
    $api_key = 'API_KEY';
    $list_id = 'LIST_ID';
    $email_to_unsubscribe = 'YOUR_EMAIL_ID';
    
    $dataCenter = substr($api_key,strpos($api_key,'-')+ 1);
    $url = 'https://'.$dataCenter.'.api.mailchimp.com/3.0/lists/'.$list_id.'/members/'.md5($email_to_unsubscribe);
    $result = json_decode(dorcode_mailchimp_curl_connect($url, 'PUT',$api_key, array('status'=>'unsubscribed')));
    if( $result->status == 400){
    	// error
        echo $result->errors[0]->message;
    } elseif( $result->status == 'unsubscribed') {
    	// success
        echo "unsubscribed";
    }
    ?>
    MailChimp delete list member.
    <?php
    $api_key = 'API_KEY';
    $list_id = 'LIST_ID';
    $email_to_unsubscribe = 'YOUR_EMAIL_ID';
    
    $dataCenter = substr($api_key,strpos($api_key,'-')+ 1);
    $url = 'https://'.$dataCenter.'.api.mailchimp.com/3.0/lists/'.$list_id.'/members/'.md5($email_to_unsubscribe);
    $result = json_decode(dorcode_mailchimp_curl_connect($url, 'DELETE',$api_key, array('status'=>'DELETE')));
    echo $result; // output "null"
    ?>
    MailChimp get all member list.
    <?php
    $api_key = 'API_KEY';
    $list_id = 'LIST_ID';
    
    $dataCenter = substr($api_key,strpos($api_key,'-')+ 1);
    $url = 'https://'.$dataCenter.'.api.mailchimp.com/3.0/lists/'.$list_id;
    $body = json_decode(dorcode_mailchimp_curl_connect($url,'GET',$api_key));
    
    // number of members in this list
    $member_count = $body->stats->member_count;
    $email = array();
     
    for( $offset = 0; $offset < ($member_count+50); $offset  = $offset+50 ) :
        $data = array(
            'offset' => $offset,
            'count'  => 50
        );
        // URL to connect
        $url = 'https://'.$dataCenter.'.api.mailchimp.com/3.0/lists/'.$list_id.'/members';
        // connect and get results
        $body = json_decode(dorcode_mailchimp_curl_connect($url, 'GET',$api_key, $data));
        foreach ( $body->members as $member ) {
        	// if($member->status=="subscribed") if you want to get members where status is subscribed
              $email[] = $member->email_address;
        }
    endfor;
    print_r($email);
    ?>
    MailChimp curl main php function.
    <?php
    function dorcode_mailchimp_curl_connect($url, $request_type, $api_key, $data = array()) {
    
    
        if( $request_type == 'GET' )
            $url .= '?' . http_build_query($data);
     
        $mch = curl_init();
        $headers = array(
            'Content-Type: application/json',
            'Authorization: Basic '.base64_encode( 'user:'. $api_key )
        );
        curl_setopt($mch, CURLOPT_URL, $url );
        curl_setopt($mch, CURLOPT_HTTPHEADER, $headers);
        //curl_setopt($mch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
        curl_setopt($mch, CURLOPT_RETURNTRANSFER, true); // do not echo the result, write it into variable
        curl_setopt($mch, CURLOPT_CUSTOMREQUEST, $request_type); // according to MailChimp API: POST/GET/PATCH/PUT/DELETE
        curl_setopt($mch, CURLOPT_TIMEOUT, 10);
        curl_setopt($mch, CURLOPT_SSL_VERIFYPEER, false); // certificate verification for TLS/SSL connection
     
        if( $request_type != 'GET' ) {
            curl_setopt($mch, CURLOPT_POST, true);
            curl_setopt($mch, CURLOPT_POSTFIELDS, json_encode($data)); // send data in json
        }
     
        return curl_exec($mch);
    }
    
    ?>
     
  • 5.11 Years

    • Category : Wordpress
    • Location : Mohali
    • Posted On : May 29, 2018

    default WooCommerce if the user clicks on the add to cart button, that item is added to the cart. if you want to add custom add to cart button please remove default "add to cart" button

    // custom template
    <button type="submit" class="custom_cart_button">add to cart</button>
    <script type="text/javascript">
    jQuery(document).ready(function() {
    var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
        jQuery('.custom_cart_button').submit(function(e) {
            jQuery.ajax({
                url: ajaxurl,
                type: "post",
                data: {				
    		action : 'post_product_variations19'
    	    },
                success: function(data) {   
                	console.log(data);
                }
            });
    	return false;
        });
    });
    </script>
    
    
    // function.php
    add_action( 'wp_ajax_nopriv_post_product_variations19', 'post_product_variations_func19' );
    add_action( 'wp_ajax_post_product_variations19', 'post_product_variations_func19' );
    function post_product_variations_func19() {
    
        global $woocommerce;
    
        $product_id = 364; // your product id
    
        $found = false;
    
        //check if product already in cart
        if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
            foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values ) {
                $_product = $values['data'];
                if ( $_product->id == $product_id ) {
                	//$calc_qty = $values['quantity'] < 1 ? 1 : $values['quantity']+1;
                	//$woocommerce->cart->set_quantity( $cart_item_key, $calc_qty, true );
                    $found = true;
                }
            }
            // if product not found, add it
            //if ( ! $found )
                $woocommerce->cart->add_to_cart( $product_id );
        } else {
            // if no products in cart, add it
            $woocommerce->cart->add_to_cart( $product_id );
        }
    	
    wp_die();
    }
  • 5.11 Years

    • Category : Css
    • Location : Mohali
    • Posted On : May 9, 2016

    this css class add your bootstrap modal then see the magic

    rotate {
        transform:rotate(180deg);
        transition:all 0.5s;
    }
    .rotate.in {
        transform:rotate(1800deg);
        transition:all 1.5s;
    }
  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Dec 16, 2015
    ALTER TABLE tablename AUTO_INCREMENT = 1
  • 5.11 Years

    • Category : Htaccess
    • Location : Mohali
    • Posted On : Dec 15, 2015

    Speed-up your website with these simple .htaccess tricks

    # Do not remove this line or mod_rewrite rules and search engine friendly URLs will stop working
    RewriteBase /
    
    # BEGIN Cache-Control Headers
    <ifModule mod_headers.c>
     <filesMatch ".(ico|jpe?g|png|gif|swf)$">
       Header set Cache-Control "public"
     </filesMatch>
     <filesMatch ".(css)$">
       Header set Cache-Control "public"
     </filesMatch>
     <filesMatch ".(js)$">
       Header set Cache-Control "private"
     </filesMatch>
     <filesMatch ".(x?html?|php)$">
       Header set Cache-Control "private, must-revalidate"
     </filesMatch>
    </ifModule>
    # END Cache-Control Headers
    
    <ifmodule mod_expires.c>
    <Filesmatch "\.(jpg|jpeg|png|gif|js|css|swf|ico|woff|mp3)$">
        ExpiresActive on
        ExpiresDefault A2592000
    </Filesmatch>
    </ifmodule>
    
  • 2.9 Years

    • Category : Jquery
    • Location : Chandigarh
    • Posted On : Mar 17, 2016
    <script type="text/javascript">
    
    var cssfeed=new gfeedfetcher("example1", "example1class", "")
    cssfeed.addFeed("CSS Drive", "your rss link") //Specify "label" plus URL to RSS feed
    cssfeed.displayoptions("date") //show the specified additional fields
    cssfeed.setentrycontainer("li") //Display each entry as a list (li element)
    cssfeed.filterfeed(10, "title") //Show 10 entries, sort by date
    cssfeed.init() //Always call this last
    
    </script>