Top Questions

  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Jul 28, 2016

    simple php rating in php

    <?php
    require "user/class.user.php";
    $auth_user = new USER();
    /********PDO Code***********/
    $email='user@gmail.com';
    $user=$auth_user->runQuery("SELECT * FROM login where email=:email");
    $user->execute(array(':email'=>$email));
    $userdatasingle=$user->fetchAll();
    $userdatasingle=$userdatasingle[0];
    ?>
    /*****HTML*******/
    <div class="rating">
                          
     <input type="hidden" name="rating" id="rating" value="<?php echo $userdatasingle["rating"]; ?>" />
           <ul onMouseOut="resetRating(<?php echo $userdatasingle["id"]; ?>);">
                 <?php
                 for($i=1;$i<=5;$i  ) {
                 $selected = "";
                 if(!empty($userdatasingle["rating"]) && $i<=$userdatasingle["rating"]) {
                 $selected = "selecteds";
                 }
         ?>
      <li class='<?php echo $selected; ?>' onmouseover="highlightStar(this,<?php echo $userdatasingle["id"]; ?>);" onmouseout="removeHighlight(<?php echo $userdatasingle["id"]; ?>);" onClick="addRating(this,<?php echo $userdatasingle["id"]; ?>);">&#9733;</li>  
                            <?php }  ?>
                        <ul>
                        <span class="ratings"><a href="#" class="Lgreen-txt font-6 rat-txt"><?php echo $userdatasingle["rating"]; ?> anmeldelser</a>
                       </span>
    </div> 
    /***********Script*************/
    <script>
    function highlightStar(obj,id) {
      removeHighlight(id);    
      $('.rating li').each(function(index) {
        $(this).addClass('highlights');
        if(index == $('.rating li').index(obj)) {
          return false; 
        }
      });
    }
    
    function removeHighlight(id) {
      $('.rating li').removeClass('selecteds');
      $('.rating li').removeClass('highlights');
    }
    
    function addRating(obj,id) {
      $('.rating li').each(function(index) {
        $(this).addClass('selecteds');
        $('#rating').val((index 1));
        if(index == $('.rating li').index(obj)) {
          return false; 
        }
      });
      $.ajax({
      url: "add_rating.php",
      data:'id=' id '&rate=' $('#rating').val(),
      type: "POST",
      success: function(data) {
      $(".rating").load(location.href " .rating>*","");
      }
      });
    }
    
    function resetRating(id) {
      if($('#rating').val() != 0) {
        $('.rating li').each(function(index) {
          $(this).addClass('selecteds');
          if((index 1) == $('#rating').val()) {
            return false; 
          }
        });
      }
    } 
    </script>
    /**********AJAX File*************/
    require "user/class.user.php";
    $auth_user = new USER();
    
    if (isset($_POST['rate']) && !empty($_POST['rate'])) {
     
        $rate = $_POST['rate'];
        $id = $_POST['id'];
    // check if user has already rated
        $sql = $auth_user->runQuery("UPDATE `login` SET rating=:rating WHERE `id`=:id");
       $sql->execute(array(':id'=>$id,':rating'=>$rate));
       
    }
     
  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Dec 23, 2015

    echo  date('Y-m-d', strtotime('-3 days'));

  • 2.9 Years

    • Category : Jquery
    • Location : Chandigarh
    • Posted On : Oct 22, 2016

    When you select multiple images using file input..after taht display all images where you wan't before upload

    <input type='file' name="image" onchange="preview(this);" multiple="multiple" />
    <div id='previewImg'></div>
    
    <script>
    window.preview = function (input) {
        if (input.files && input.files[0]) {
            $(input.files).each(function () {
                var reader = new FileReader();
                reader.readAsDataURL(this);
                reader.onload = function (e) {
                    $("#previewImg").append("<img class='thumb' src='"   e.target.result   "'>");
                }
            });
        }
    }
    </script>
     
  • 2.9 Years

    • Category : Jquery
    • Location : Chandigarh
    • Posted On : Jan 25, 2017

    You can change background of container using this code

    Html:
    
    <form class="form-inline">
         <div class="form-group">
          <label for="fileToUpload"> <img src="images/upload.png'; ?> " width="200" height="100" id="blah1" /></label>
           <div class="input-group">
      <input type="file" name="exmaple" id="fileToUpload"  required>
      <input type="hidden" id="backupimgurl" val="">
     </div>
      </div>
            <div class="form-group">
        <div class="input-group">
     <select class="form-control" onchange="$('#home-page').css({'background-position':$(this).val()});" name="BackgroundPosition" id="BackgroundPosition">
        <option value="center" selected="selected">Center</option>
        <option value="center top">Center/Top</option>
        <option value="center bottom">Center/Bottom</option>
        <option value="left center">Left/Center</option>
        <option value="left top">Left/Top</option>
        <option value="left bottom">Left/Bottom</option>
        <option value="right center">Right/Center</option>
        <option value="right top">Right/Top</option>
        <option value="right bottom">Right/Bottom</option>
      </select>
     </div>
     </div>
     <div class="form-group">
      <div class="input-group">
      <select class="form-control" onchange="$('#home-page').css({'background-repeat':$(this).val()});" name="BackgroundImageRepeat" id="BackgroundImageRepeat">
       <option value="repeat-x">Repeat Horizontal</option>
       <option value="repeat-y">Repeat Vertical</option>
       <option value="repeat">Repeat</option>
        <option value="no-repeat" selected="selected">No Repeating</option>
          </select>
      </div>
    </div>
    <div class="form-group">
      <div class="input-group">
       <input class="form-control" value="" name="BackgroundColor" style="width:80%; display:inline-block;" maxlength="6" placeholder="color">
     </div>
      </div>
     <div class="form-group">
     <div class="input-group">
         <button type="submit" class="btn btn-success">Save</button>
         </div>
          <div class="input-group">
         <button type="submit" class="btn btn-danger">Cancel</button>
        </div>
       </div>
    </form>
    
    jQuery:
    
    jQuery(document).on('change','#fileToUpload',function(){
     var imgbg = window.URL.createObjectURL(this.files[0]);
      jQuery('#backupimgurl').val(imgbg);
       //console.log(imgbg);
     jQuery('#home-page').css({backgroundImage: "url(" imgbg ")"});
    });
    
  • 5.11 Years

    • Category : Magento
    • Location : Mohali
    • Posted On : Jul 7, 2016

    This tutorial shows how to add page links to Magento navigation bar. In order to add the page links to the navigation bar, you should perform the following steps:

    Step 1: Adding the Subcategory
     
    1. Go to Catalog -> Manage Categories in your Magento Admin.

    2. Select ‘Default Category’ on the left, then click the ‘Add Subcategory’ button:
    3. Fill in the fields:
    4. – Specify your link Name.
    5. – Set ‘Is Active’ to Yes.
    6. – In the URL Key field type the name of your page link in lowercase letters with hyphens instead of spaces (f.e.’About Us’ becomes about-us):
    7. – Scroll down to the bottom of the form and set Include to Navigation Menu to ‘yes’.
    8. – Click ‘Save Category’ button:
     

    Step 2: Creating a Redirect
     

    1. Navigate to Catalog -> URL Rewrite Management.
    2. In the search box of the Request Path column, type in the URL key for the subcategory, and click Search.
    3. When the subcategory is located, click ‘Edit’ to open the record:
    4. NOTE: you will have records for each installed language. You can open the record for each language in the new browser tab.
    5. Open the notepad on your PC and save the following info: the ID path of your URL Rewrite and the Request path:
    6. Now we should delete the URL Rewrite for each language – click the Delete button at the top right.

    Step 3: Adding a new URL rewrite
     
    1. In Catalog -> URL Rewrite Management click Add URL Rewrite button at the top right.

    2. In the Create URL Rewrite field select ‘Custom’.

    3. Fill in the URL Rewrite Information form:

      – Add the ID path for the item which you have noted and saved in the notepad on step 2.2.

      – Add the Request Path for the item which you have noted and saved in the notepad on step 2.2.

      – To fill in the Target Path field, open any navigation menu on your site and copy-paste its url into the field, f.e: http://yourdomain.com/index.php/contacts/ (where ‘contacts’ is the Request Path for the Contact Us navigation page). Replace the Request Path with the new item Request Path which you have noted and saved in the notepad on step 2.2 of this tutorial.

    4. Set Redirect to ‘Permanent 301′.

    5. Click ‘save’ button at the top right:
       

    Step 4: Creating a page
     
    1. Go to CMS -> Pages.

    2. Click ‘Add New Page’.

    3. Specify the page title, the URL key for the page, select All Store Views:

    4. Switch to the Content Tab on the left. Put the html for your page content here.

    5. Switch to the Design Tab on the left. In the layout field choose the desired Page Layout:

    6. Click ‘Save Page’

    Step 5: Clearing your Magento Cache

    This is the end of the tutorial. You’ve learned how to add page links to Magento navigation bar
  • 5.11 Years

    • Category : Php
    • Location : Mohali
    • Posted On : Nov 23, 2017

    There's a bug in Wordpress 4.9, I discovered this temporary super code. I plan on uninstalling it once they fix the bug, but it works great in the meantime!

    global $wpdb;
    $wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE '_transient_files_%' LIMIT 1" );
     
  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Feb 17, 2018

    Website visitor using php.

    $datei = fopen(APPPATH."/cache/countlog.txt","r");
    $count = fgets($datei,1000);
    fclose($datei);
    $count=$count +  1 ;
    echo "$count" ;
    // opens countlog.txt to change new hit number
    $datei = fopen(APPPATH."/cache/countlog.txt","w");
    fwrite($datei, $count);
    fclose($datei);
  • 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 : Wordpress
    • Location : Mohali
    • Posted On : May 27, 2016

    I am fairly new to woocommerce and although the other day the add to cart and cart page was displaying fine. I am now finding that going to my cart page brings up a blank page.

    add this code in function.php
    add_filter('woocommerce_add_to_cart', 'custome_add_to_cart');
    function custome_add_to_cart() {
        global $woocommerce;
     $woocommerce->session->set_customer_session_cookie(true);
    }
     
  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Dec 30, 2015
    echo mt_rand(1, 9999999);