Top Questions

  • 5.11 Years

    • Category : Php
    • Location : Chandigarh, India
    • Posted On : Jul 31, 2016

    In order to generate token for access to api and other

    Here is the correct solution:
    $token = bin2hex(openssl_random_pseudo_bytes(16));
     
  • 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>

     

  • 5.11 Years

    • Category : Wordpress
    • Location : Chandigarh, India
    • Posted On : May 29, 2018

    To disable this update notification, there is no switch in the settings menu or anywhere else in the admin dashboard. To prevent WordPress from showing these information snippets on top of your WordPress dashboard, you shall need to add a PHP code snippet to your functions.php file.

    add_filter('pre_site_transient_update_core','__return_null');
    add_filter('pre_site_transient_update_plugins','__return_null');
    add_filter('pre_site_transient_update_themes','__return_null');
     
  • 5.11 Years

    • Category : Wordpress
    • Location : Chandigarh, India
    • Posted On : Mar 15, 2018

    You can specify a function identifier in a custom property in your .ajax() call and use the value of that in your ajaxComplete() callback.

    For example, get any ajax property while making your .ajax() call:
    function foo() {
        $.ajax({
            url: 'my-page.php',
        });
    }
    
    And then, use any of ajax property to ajaxComplete() like this:
    $('#my-unique-id').ajaxComplete(function(e, xhr, settings) { // run after all ajax complete 
        if (settings.url == 'my-page.php') { // write condition according to your requirement
            // execute you code
        } else {
            // execute you code
        }
    });
     
  • 2.9 Years

    • Category : Wordpress
    • Location : Chandigarh
    • Posted On : Apr 1, 2016

    Upload multiple video file and store its in database using this code.

    <?php
    $server_url="http://".$_SERVER['SERVER_NAME'].dirname($_SERVER["REQUEST_URI"].'?').'/';
    $path = preg_replace('/wp-content.*$/','',__DIR__);
    $path = preg_replace('/wp-content(?!.*wp-content).*/','',__DIR__);
    include($path.'wp-load.php');
    /******Database Connect end*******/
    if(isset($_POST['add']))
    {
    $_FILES["fileToUpload"]["name"];
    if ( ! function_exists( 'wp_handle_upload' ) ) {
    require_once( ABSPATH . 'wp-admin/includes/file.php' ); }
    $upload_overrides = array( 'test_form' => false );
     $files = $_FILES["fileToUpload"]; 
        foreach ($files['name'] as $key => $value) {           
                if ($files['name'][$key]) {
                    $file = array(
                        'name' => $files['name'][$key],
                        'type' => $files['type'][$key],
                        'tmp_name' => $files['tmp_name'][$key],
                        'error' => $files['error'][$key],
                        'size' => $files['size'][$key]
                    );
    
                   $_name = $file['name'];
                   $f_name =  explode('.', $_name);
                    $rand = rand(0000,9999);
                   $addname = $f_name['0'].$rand;
                   $total_name = $addname."." .$f_name['1'];
    
                  $insertname[] = $total_name;
    
    
    
                   $file_s = array( 'name' =>  $total_name,
                        'type' => $files['type'][$key],
                        'tmp_name' => $files['tmp_name'][$key],
                        'error' => $files['error'][$key],
                        'size' => $files['size'][$key]
                    );
    
    
    
    
                 
    
                    
                        $newupload = wp_handle_upload($file_s,$upload_overrides);
                      $patoooooooooh[] = $newupload['url'];
                   
                }
            }
    $nname=implode("&",$patoooooooooh);
    mysql_query("insert table_name (`column_name`) values ('$nname')");
    }
    ?>
    /*****Php Code end and html start*****/
    <form class="form-horizontal" method="post" enctype="multipart/form-data">
    <input type="file" name="fileToUpload[]" id="fileToUpload" class="add_file">
    <div class="demo">
    </div>
    <button name="add" type="submit">Add</button>
    </form>
    /********Html End & jquery Start**************/
    
    <script>
    $(document).ready(function() {
    // $('.add_field_button').keyup(function(e){
      var rand=Math.random();
    $(document).on('change','.add_file',function(e){
      //on add input button click
            e.preventDefault();
                $('.demo').append("<div class='sas'><br/><input type='file' name='fileToUpload[]' class='add_file' ><a href='#' class='remove_field'><i class='fa fa-trash-o'></i></a></div>"); //add input box
        });
      $('.demo').on('click', '.remove_field', function(e) {
        $(this).closest('.sas').remove();
      return false;
    });
    });
    </script>
  • 5.11 Years

    • Category : Php
    • Location : Chandigarh, India
    • 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" );
     
  • 5.11 Years

    • Category : Php
    • Location : Chandigarh, India
    • Posted On : Apr 21, 2016

    Return all dates or time between two dates in an array

    print_r(createDateTimeRangeArray('2007-01-15 11:15:00', '2007-01-20 18:15:00','  1 day','d/m/Y h:i:s A'));
    
    
    function createDateTimeRangeArray($start,$end,$step = '  30 minutes',$output_format = 'H:i') {
      $range = array();
     if (is_string($start) === true) $start = strtotime($start);
     if (is_string($end) === true ) $end = strtotime($end);
      if ($start > $end) return createDateTimeRangeArray($end, $start);
      do {
        //$range[] = date('Y-m-d', $start);
       $range[] = date($output_format, $start);
        $start = strtotime($step, $start);
      }
     while($start < $end);
      return $range;
    } 
  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Aug 18, 2016

    Drag Drop your table's data using jQuery,Ajax,php and mysql

    /**********HTML PART START**************/
    
    <div class="x_content my-data" id="">
    
                      <table class="table table-bordered">
                        <thead>
                          <tr>
                            <th>#</th>
                            <th>Image</th>
                            <th>Category</th>
                            <th>Edit</th>
                            <th>Delete</th>
                          </tr>
                        </thead>
    <?php
      
      $query = "SELECT * FROM product ORDER BY pos ASC";
      $result = mysql_query($query) or die(mysql_error().': '.$query);
      if(mysql_num_rows($result)) {
    ?>
    <form id="dd-form" action="" method="post">
      <input type="checkbox" value="1" name="autoSubmit" id="autoSubmit" class="autoooo" checked/>
    <tbody id="sortable-list">
      <?php 
        $order = array();
        $i=1;
        while($row = mysql_fetch_assoc($result)) {
            $img=explode(",",$row['product_img']);
                           $img=explode(",",$row['product_img']);
    $catqry=mysql_fetch_array(mysql_query("select * from category where id='".$row['product_cat_id']."'"));
    $scatqry=mysql_fetch_array(mysql_query("select * from subcategory where id='".$row['product_subcat_id']."'"));
    
                           echo '<tr title="',$row['id'],'"><td>',$i,'</td><td><img src="',$img[0],'" height="50" width="50"></td><td>',$catqry['cat_name_eng'].'/'.$catqry['cat_name_china'],'</td><td><a href="?edit=',$row['id'],'"><i class="fa fa-pencil"></i></a></td><td><a href="?delete=',$row['id'],'" onclick="return confirm("Are you sure you want to delete")"><i class="fa fa-trash"></i></a></td></tr>';
          $order[] = $row['id'];
          $i  ;
        }
      ?>
    </tbody>
    <br />
    <input type="hidden" name="sort_order" id="sort_order" value="<?php echo implode(',',$order); ?>" />
    </form>
    <?php } ?>
    
    
                      </table>
    
                    </div>
                  </div>
            
            </div>
    <style type="text/css" media="screen">
    #sortable-list1   { padding:0; }
    #sortable-list1 tr  { padding:4px 8px; color:#000; cursor:move; list-style:none; width:100px; background:#ddd; margin:10px 0; border:1px solid #999; }
    #sortable-list1 tr td { text-align: center; }
    #message-box1   { padding:4px 8px; margin:0 0 14px 0; width:500px; }
    .autoooo{ display : none; }
    </style>
    /**********HTML PART END**************/
    /**********SCRIPT PART START**************/
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
      <script>
    /* when the DOM is ready */
    $(document).ready(function() {
    
      /* grab important elements */
      var sortInput = $('#sort_order');
      var submit = $('#autoSubmit');
      var messageBox = $('#message-box');
      var list = $('#sortable-list');
      /* create requesting function to avoid duplicate code */
      var request = function() {
      $.ajax({
      url: "drop_ajax.php",
      data:'sort_order='   sortInput[0].value   '&ajax='   submit[0].checked   '&do_submit=1&byajax=1',
      type: "POST",
      success: function(data) {
            window.location.reload();
      }
      });
      };
      /* worker function */
      var fnSubmit = function(save) {
       
        var sortOrder = [];
        list.children('tr').each(function(e){
          sortOrder.push($(this).data('id'));
        });
        sortInput.val(sortOrder.join(','));
       // console.log(sortInput.val());
        if(save) {
          request();
        }
      };
      /* store values */
      list.children('tr').each(function(e) {
        var tr = $(this);
        tr.data('id',tr.attr('title')).attr('title','');
      });
      /* sortables */
      list.sortable({
        opacity: 0.7,
        update: function() {
          fnSubmit(true);
        }
      });
      list.disableSelection();
    });
    </script>
    /**********SCRIPT PART END**************/
    /**********AJAX PART START**************/
    <?php
    include('config.php'); /include your db file here
    /* on form submission */
    if(isset($_POST['do_submit']))  {
      /* split the value of the sortation */
      $ids = explode(',',$_POST['sort_order']);
     /* run the update query for each id */
      foreach($ids as $index=>$id) {
       $id = (int) $id;
        if($id != '') {
         $query = 'UPDATE product SET pos = '.($index   1).' WHERE id = '.$id;
         $result = mysql_query($query) or die(mysql_error().': '.$query);
        }
     }
     
      /* now what? */
     if($_POST['byajax']) { die(); } else { $message = 'Sortation has been saved.'; 
     
      echo $message;
      }
    }
    ?>
    
    
    /**********AJAX PART END**************/
  • 2.9 Years

    • Category : Jquery
    • Location : Chandigarh
    • Posted On : Jul 5, 2017

    Get geo location using jquery and save in a cookie

    var jb_lat = getCookie('jb_lat');
    var jb_lng = getCookie('jb_lng');
    
    if(jb_lat == '' && jb_lng == ''){
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(showPosition);
        } else { 
            x.innerHTML = "Geolocation is not supported by this browser.";
        }
        function showPosition(location){
            var exdays = 10;
            var d = new Date();
            d.setTime(d.getTime()   (exdays*24*60*60*1000));
            var expires = "expires="  d.toUTCString();
            document.cookie = "jb_lat="   location.coords.latitude   ";"   expires   ";path=/";
            document.cookie = "jb_lng="   location.coords.longitude   ";"   expires   ";path=/";
            window.location.reload();
        }
    
    }
        function getCookie(cname) {
            var name = cname   "=";
            var decodedCookie = decodeURIComponent(document.cookie);
            var ca = decodedCookie.split(';');
            for(var i = 0; i <ca.length; i  ) {
                var c = ca[i];
                while (c.charAt(0) == ' ') {
                    c = c.substring(1);
                }
                if (c.indexOf(name) == 0) {
                    return c.substring(name.length, c.length);
                }
            }
            return "";
        }
  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Jan 7, 2016
    if(isset($_GET['mintime']) && isset($_GET['maxtime'])){
        $extraconditionsa = $extraconditionsa ."and TIME_FORMAT (
       str_to_date (
           replace (hour,':',''),'%H%i'),'%H:%i') between '{$_GET['mintime']}' AND '{$_GET['maxtime']}'";
    }
    
    // mysql:How do I check if a column is empty or null in mysql
    SELECT * FROM table_name WHERE NULLIF(some_col, '') IS NULL;