Saturday, December 19, 2015

how to create RSS Feed


<?php echo '<?xml version="1.0" encoding="UTF-8" ?>';?>
 <rss version="2.0">
    <channel>
        <title>BhojpuriTrain.com</title>
        <description>Free Bhojpuri song download</description>
        <link>http://bhojpuritrain.com</link>      
       
        <item>
            <title>BhojpuriTrain.com</title>
            <description>Watch PK2 Comedy Short Film directed by SRikanth Reddy PK2 is a hilarious Hindi short film spoof</description>
            <link>http://bhojpuritrain.com/player.php?v=LHu3_CXEdJY</link>
            <pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate>  
        </item>
       
        <item>
            <title>A 2 year old cute kid Dugu answering the quote answer</title>
            <description>Must watch how this cute boy answering</description>
            <link>http://bhojpuritrain.com/player.php?v=od0YNytKPCo</link>
            <pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate>  
        </item>
                       
        <item>
            <title>a very cute dance by village boy</title>
            <description>must see how a little kid dancing</description>
            <link>http://bhojpuritrain.com/player.php?v=didoFn8Erf0</link>
            <pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate>  
        </item>      
       
    </channel>
</rss>

Friday, December 18, 2015

PHP Tutorials Dynamic RSS Feed For Your Website Content Part 3 3

PHP Tutorials Dynamic RSS Feed For Your Website Content

Thursday, December 17, 2015

Make Download link and force to download on browser using PHP

$name  = $_GET['name'];
$fname = $_GET['file_name'];

$dir_path  = __DIR__.'/../uploads/';

header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header("Content-Disposition: attachment; filename=\"" . $name . "\";");
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($dir_path.$fname));
ob_clean();
flush();

readfile($dir_path.$fname);
exit;

Saturday, October 17, 2015

===================== Don't Buy Lenovo K3 note.. ==========================



after using this phone since last 2 week i have nothing than regret myself.
lenovo owner are trying to tag this product as Luxury Brand but in reality its a shit.
200% i will tell you that levono has worst developer and    tester who don't know the market needs.

why i am angry. read below

1. its lagging alot even i had not installed too many Apps. (i have M-indicator, slack, GreyTipHr whatsapp, google hangout)

2. if you plug ur charger into laptop and start any application (try camera ) it will tale enough time to make you angry.

3. if you will use another charger (even in wall socket ) device will show "its charging" when its not charging. in evening 7 PM i plunged carbon charger and when i back 7:40 PM, you will not believe it but i found same 42% as it was before.

4. even with lenevo charger, my device is not charging via laptop. (in 30 mnt i am getting 1% increment in charging.)

only camera is good nothing else. if they can return my money or replace with other phone..it will be great help for me.

Suggestion for lenevo Dev-: Wearing nice jacket, shoes and googles will not make you popular, you should be nice by your karma...(designing the nice UI is not all About, care about your functionality)

Worst product Ever i found.

Monday, October 12, 2015

Disable cell broadcast notifications on Lenovo K3 Note

Go to Message Setting    -> 
                                        -> Cell Broadcast 
                                        ->   Select Provide 
                                        -> Uncheck the "ETWS Alert".

Thursday, October 8, 2015

what is the simple concept for pagination

pagination required mathematics..
its easy to make any kind of pagination.

lets have a look in php.

<?php
$current_page=((isset($_REQUEST['page']) && ($_REQUEST['page']!=""))?$_REQUEST['page']:1);
$next_page=$current_page+1;
$page_limit=5;
$page_from=(($current_page*$page_limit)-$page_limit);
echo $page_from.'-'.$page_limit;
?>


Hit url like http://yourdomain.com?page=1

Hit url like http:127.0.0.1/myprojec_page.php?page=1

Detect MouseWheel via javascript and do auto scroll as MouseWheel scroll.

Useful code for developers.

// detect mouse wheel and do scroll as per
if (document.addEventListener) {
    document.addEventListener("mousewheel", MouseWheelHandler(), false);
    document.addEventListener("DOMMouseScroll", MouseWheelHandler(), false);
} else {
    sq.attachEvent("onmousewheel", MouseWheelHandler());
}


function MouseWheelHandler() {
    return function (e) {
        // cross-browser wheel delta
        var e = window.event || e;
        var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));

        //scrolling down?
        if (delta < 0) {
           // alert("Down");
        }

        //scrolling up?
        else {
            // alert("Up");
        }
        return false;
    }
}

Click here for demo

Tuesday, September 29, 2015

filter_input list in php

These are the filter_input list which is very useful. 


    [0] => int
    [1] => boolean
    [2] => float
    [3] => validate_regexp
    [4] => validate_url
    [5] => validate_email
    [6] => validate_ip
    [7] => string
    [8] => stripped
    [9] => encoded
    [10] => special_chars
    [11] => unsafe_raw
    [12] => email
    [13] => url
    [14] => number_int
    [15] => number_float
    [16] => magic_quotes
    [17] => callback

Wednesday, September 23, 2015

Set limit of selection in multiple select box in html

HTML code
<select multiple id='testbox'>
      <option value='1'>First Option</option>
      <option value='2'>Second Option</option>
      <option value='3'>Third Option</option>
      <option value='4'>Fourth Option</option>
      <option value='5'>Fifth Option</option>
      <option value='6'>Sixth Option</option>
      <option value='7'>Seventh Option</option>
      <option value='8'>Eighth Option</option>
      <option value='9'>Ninth Option</option>
      <option value='10'>Tenth Option</option>
    </select>

JavaScript code
var last_valid_selection = null;
      $('#testbox').change(function(event) {
        if ($(this).val().length > 5) {
          alert('You can only choose 5!');
          $(this).val(last_valid_selection);
        } else {
          last_valid_selection = $(this).val();
        }
      });

Output



Sunday, September 13, 2015

validate each and every form in entire application with same javascript code with individual error message

Have a look


JavaScript Code


$('body').on('click', '.btn_class', function(event) {
var bnt_cntrl=$(this).attr('id');
var form_elmnt= $(this).parents('form.form1');
var action=form_elmnt.attr("action");
var error_msg_box=form_elmnt.find('.errorBox');
//alert(error_msg_box);
is_done=0;
form_elmnt.find('.errorBox').empty().append('<ol/>');
form_elmnt.find(':input[is_required="1"]:not(:disabled)').each(function(index, element) {
//alert(1);
var type = this.type || this.tagName.toLowerCase();
//alert(type);
if(type=="select-one"){ 
var currencty_id=$(this).attr("id");
var is_empty=$("#"+currencty_id+" option:selected").val();
}
else{ 
var is_empty=$(this).val();
 }
if(is_empty=="" || is_empty==null || is_empty=='Na' || is_empty=='Null' || is_empty==0){ // if null keyword specified as string 
var error_msg=$(this).attr('err_msg');
if(error_msg=="" || error_msg==null || error_msg=='undefined'){ // if your error_msg and placeholder are same then just skip error_msg tag
error_msg = $(this).attr('placeholder');
}
error_msg_box.find('ol').append('<li>'+error_msg+'</li');
is_done++;
//window.scrollTo(0,0);
false;
}
});
if(is_done==0){
var ajaxMsg='';
error_msg_box.empty();
error_msg_box.append("<div class='welcome_msg'><h3>Please wait.form is beinging submited</h3></div>").slideUp(100).slideDown(50);
var form_data=$(form_elmnt).serialize();
ajaxResponce=send_request(bnt_cntrl,'controller/ajax.php',form_data,error_msg_box);
try {
     JsonDataSet  = JSON.parse(ajaxResponce);
     ajaxMsg      = JsonDataSet[0];
   var ajaxValue    = JsonDataSet[1];
} catch(e) {
    ajaxMsg=ajaxResponce; // if server return only string 
}

if(ajaxMsg=="done"){
var custom_msg='';
if(bnt_cntrl=='add_new_client'){
var timing=1000;
custom_msg="New Client has been added";
error_msg_box.addClass('doneMsg').html(show_done_msg(custom_msg,'?r=add_office&client_id='+ajaxValue+'&lock=1',true,timing)); // page will be redirect after 5 second
$('.redirect_to').html('page will be redirect in '+timing+' milisecond');
}
else if(bnt_cntrl=='add_new_office'){
                 custom_msg='<h2>New office has been created now.</h2>\
<p>Would you like to add More Offices</p>\
<a href="javascript:void(0)" data-role="yes" id="yes_add_more_office">Yes</a>\
<a href="javascript:void(0)" data-role="no" id="no_more_office">no</a>';
$(this).attr('disabled','disabled');
/*var table_elmnt=$('.add_office_table tbody');
var this_region=form_elmnt.find('#regionBox option:selected').text();
var this_country=form_elmnt.find('#country option:selected').text();
var this_zip=form_elmnt.find('#zip').val();
var this_entity_name=form_elmnt.find('#entity_name').val();
table_elmnt.append(
'<tr>\
<td><!--it will auto append by re_arrange Method --></td>\
<td>'+this_region+'</td>\
<td>'+this_country+'</td>\
<td>'+this_zip+'</td>\
<td>'+this_entity_name+'</td>\
<td><i class="fa fa-minus-circle temp_office_row"></i></td>\
</tr>'
);
var panel_1=form_elmnt.find('.form_elements');
var panel_2=form_elmnt.find('.status_elements');
togglePanel(panel_1,panel_2); 
panel_2.html(custom_msg);
re_arrange(table_elmnt,'input[name="is_office_added"]'); */
}
else if(bnt_cntrl=='add_new_employee'){
custom_msg="New employee has been added";
error_msg_box.addClass('doneMsg').html(show_done_msg(custom_msg,'',false,timing)); // page will be redirect after 5 second
//$('.redirect_to').html('page will be redirect in '+timing+' milisecond');
}
//error_msg_box.addClass('doneMsg').html(show_done_msg('sudhir','?r=abcd'));
/*
error_msg_box.addClass('doneMsg').html('<div>\
<i class="fa fa-check-circle bigTick"></i>&nbsp;\
<h2>'+custom_msg+'</h2>\
<i class="btmGap">\
<a href="javascript:void(0)" onclick="javascript:location.reload()">\
Click here to reload page\
</a>\
</i>\
</div>');
*/
$(this).attr('disabled','disabled');
form_elmnt.find('.client_elmnt_box').slideUp(1);
//$('.client_elmnt_box').slideUp(100);
}
else{
error_msg_box.html(ajaxMsg);
return false;
}
}
else{
error_msg_box.show(100);
}
});

HTML form

 <form action="#" class="form1">
       <div class="form_elements">

<div class="col-md-6">
                            <div class="form-group">
                                <div class="input-icon">
                                <label class="txt-normal">Office In time<?php echo star_mark;?></label>
                                <i class="fa fa-clock-o"></i>
                                <input name="office_open_time" value="" type="text" class="form-control" id="opt1" placeholder="enter office opening time as hhmmss skg" is_required="1" err_msg="enter your custom_msg here" />
                                </div>
                            </div>
                        </div>
</div>
</div>
</form>

Sunday, September 6, 2015

how to make a php file with executable array

In this Article, i am trying to make a model file (php ) for table called user_table.

file will  be save in table_name.php


<?php
public function create_model($dataSet=""){

$table_name=$dataSet['table'];
$str_open='<?php $'.$table_name.' = ' ;
$get_table_info=array();
//$str.='$'.$table_name.'=array(';
$table_info=new general;
$get_table_info=$table_info->get_table_schema($table_name); // fetch table column from database
$str_close=' ?>';
$new_model_file_name=__DIR__.'/../model/'.$table_name.'.php';
try{
$done=file_put_contents($new_model_file_name, $str_open.' '.var_export($get_table_info, true).'; return $'.$table_name.'; '.$str_close);
//echo 'Model <b>'.$table_name.'</b> has been created';
echo 'done';
}
catch(Exception $e){
echo 'oops there is some error to write new model';
}

/*
$b=include_once($new_model_file_name);
echo '<pre>';
print_r($b);
echo '</pre>';*/
}
?>

Saturday, September 5, 2015

How to make responsive (YouTube) frame

Dear friend,
However embedding an Iframe is not good as per SEO. but i will tell you the technique to add responsive Iframe.

1. HTML Code

<div class="embed-player">          
                    <div class="h_iframe">
                       <img class="ratio" src="http://bhojpuritrain.com/ico/loading.png" />
<script>
document.addEventListener("DOMContentLoaded", function(event) {
get_player('<?php echo $_REQUEST['v']?>') //do work
});
                            </script>                    
                    </div>
                    <div class="total_view">Total Views-:
                        <?php echo ($video_details['total_views']+1); ?>
                    </div>
                    <div class="description">
                        <?php echo preg_replace('/[^\x20-\x7E]/', '',$video_details['description']); ?>
                    </div>
                </div>



2. CSS

.h_iframe {
position: relative;
height:auto;
}

.h_iframe .ratio {
display: block;
width: 100%;
height: auto;
}

.h_iframe iframe {
/*position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
*/

width: 100%;
height: 100%;
min-height: 400px;
}





3. JavaScript Code

function get_player(video_id){
window.setTimeout(function(){
$('.h_iframe').html('<iframe src="https://www.youtube.com/embed/'+video_id+'" frameborder="0" allowfullscreen></iframe>');
},1000) // frame will load after one second
}


Thursday, September 3, 2015

how to put developer codes into blog or website with line number

If you are blogger  or wishing to post any tech blog.. then you must need to put codes with line number in your article.

I made a simple way to get this issue.


Have a look.

http://sudhirgupta.comyr.com/99crashpoint/codeline.php

Friday, August 28, 2015

Simple and easiest Pagination in PHP with PDO

Pagination in 5 minute

Try out my function to achieve pagination


<?php
function data($limit_2=10){
$page=(!isset($_REQUEST['page'])?1:$_REQUEST['page']);
$limit_1=($limit_2*$page)-$limit_2;
$link=include 'config.php';
$data_set=array();
$sql=$sql_for_pagination="select * from clients order by id desc";
$sql.=' limit '.$limit_1.", ".$limit_2;
$query_c=$link->query($sql_for_pagination);
$total_records=$query_c->rowCount();

echo $sql.'<br />';
// fetch data
$query = $link->prepare($sql);
$query->execute();
if($query->rowCount()){
$total_pages = ceil($total_records / $limit_2);
$pagination='';
for($p=1;$p<=$total_pages;$p++){
$pagination.='<a href="?page='.$p.'">'.$p.'</a>&nbsp; &nbsp;';
}
$pagination.='</div>';
$data_set['pagination']=$pagination;
$data_set['total_data'] = $query->fetchAll(PDO::FETCH_ASSOC);
return $data_set;
}
else{
return 'no record found';
}
}
$data=data(5);
echo '<pre>';
print_r($data);
echo '</pre>';
?>

Thursday, August 27, 2015

Connect DataBase using PDO in PHP

While mysql_connect has been depreciate, there is only two way to connect database in php
1.  mysli_
2. PDO (the best and safest way).

below  is the code

<?php
define ('DB_HOST', "127.0.0.1");
define ('DB_USER', "root");
define ('DB_PASSWORD', "");
define ('DB_DATABASE', "database_name");
    try
    {
        $pdo = new PDO('mysql:host='. DB_HOST .';dbname='.DB_DATABASE, DB_USER, DB_PASSWORD);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo 'its connect';
    }
    catch (PDOException $e)
    {
$pdo='Error: '.$e->getMessage();
die('DB execution failed due to this error <br />'.$e->getMessage());
    }
//print_r($pdo);
return $pdo;

?>

Tuesday, August 25, 2015

get current url query string and change then redirect. (modifying URL in PHP)

lets say your current url is
abcd.com/index.php?r=employee_list&search=sudhir&l1=0&l2=5

where l1= limit 1
and  l2= limit 2

you want to make pagination and want to change the limit 1 value.

code

$_GET['l1']=6;
$queryString = http_build_query($_GET, '', '&');

now  your query is r=employee_list&search=sudhir&l1=6&l2=20

header ("Location: http://abcd.com/".$queryString ); // redirect to same page with new range

Sunday, August 23, 2015

how to find total number of record with limit parameter in mysql

#1          
  $stmt = $this->link->prepare("SELECT *,(SELECT COUNT(*) FROM clients) total_count                  FROM clients LIMIT 0, 10");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$rowcount = $rows[0]['total_count'];
echo $rowcount; // return total number of row
                print_r($rows);  // return data



#2

$query = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM table WHERE name LIKE 'a%' LIMIT 0,50");
$query_count = mysql_query("SELECT FOUND_ROWS()");
$result = mysql_fetch_array($query_count);
$total_num_rows = $result[0];

/* HERE IS YOUR CODE PARCING THE RESULTS OF MAIN QUERY */

#3 using PDO

 $query = $this->link->query("SELECT SQL_CALC_FOUND_ROWS * FROM clients LIMIT 0,50");
 $query_count = $this->link->query("SELECT FOUND_ROWS()");
 $result = $query_count->fetchAll(PDO::FETCH_ASSOC);
 $total_num_rows = $result[0];
 print_r($total_num_rows);

Wednesday, August 19, 2015

find any elemnts height and width in object formate using javascript

<code>
<script>
var ul = $('.TokensContainer');
var p=ul.outerWidth(Math.max(ul.width('').outerWidth()));
alert('height is - '+p[0]['clientHeight']);
console.log(p);
</script>
</code>
must check in console.log

Thursday, August 13, 2015

How to detect when that enter key is pressed inside a TextBox or somewhere else ?

How to detect when that enter key is pressed inside a TextBox or somewhere else ?




$('form input').live("keypress", function(e) {
        if (e.keyCode == 13) {
//put your logic here
             alert('enter key has been pressed inside the textbook');
            return false; // prevent the button click from happening
        }
});


Thursday, July 23, 2015

How to create customized unique id like YouTube video id


Dear friend,
Some time we need to generate unique id for your clietns. we can use mysql generator id if we need to use that Id in printing.

for example.
you are creating bill for your client. you need to mention client id. if you will enter client id -:1, it wont look good.

so i write some code to achieve this goal.

Code 1-: 

function idGenerator1($length) {
  $random = '';
  for ($i = 0; $i < $length; $i++) {
    $random .= chr(rand(ord('a'), ord('z')));
  }
  $random .= rand(0, 1) ? rand(0, 9) : chr(rand(ord('a'), ord('z')));
  return  strtoupper($random);
}

Wednesday, June 24, 2015

submit form with form.serialise and parse the data into php

JS Things


function submitData(){
var dataString = $('form').serialize(); // your data will serialize
console.log("check data-: \n \t "+dataString);
$.ajax({
type:'POST',
url: "path/to/file.php",
data:{'validateMe':dataString}
}).done(function(msg) {
console.log(msg);
}).fail(function(jqXHR, textStatus) {
alert( "Request failed: " + textStatus_jqXHR );
 });
return false;
}


-------------------------------

PHP  Things

<?php
if(isset($_REQUEST['validateMe']))

$data=$_REQUEST['validateMe'];
parse_str($_REQUEST['validateMe'],$data);

echo '</pre>';
print_r($_REQUEST['data']);
print_r($_data); // this is your formatted Data.
echo '</pre>';
?>

Use the JavaScript width() method

You can set the width of a <div> box dynamically using the jQuery width() method.
The width() method simply returns the element's width as unit-less pixel value. However calling the width(value) method sets the width of the element, where the value can be either a string (e.g. 100%50px25emauto etc.) or a number. If only a number is provided for the value, jQuery assumes it as a pixel unit.


Copy Code Below

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery Set a DIV width</title>
<style type="text/css">
    .box{
        float: left;
        background: #f2f2f2;
        border: 1px solid #ccc;
    }
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $(".set-width-btn").click(function(){
        var newWidth = $(".input-width").val();
        $(".box").width(newWidth);
    });
});
</script>
</head> 
<body>
    <form>
        <input type="text" class="input-width">
        <button type="button" class="set-width-btn">Set Width</button>
        <p>Enter the value in input box either as number (e.g. 100, 200) or combination of number and unit (e.g. 100%, 200px, 50em, auto) and click the "Set Width" button.</p>
    </form>
    <br>
    <div class="box">This is simple DIV box</div>
</body>
</html>

How to bind click event if HTML elements added dynamically in jQuery

If you try to do something with the elements that are dynamically added to DOM using the jQuery click() method it will not work, because it bind the click event only to the elements that exist at the time of binding. To bind the click event to all existing and future elements, use the jQuery on() method. Check out the following example.



Copy Code Below

<html lang="en"> <head> <meta charset="utf-8"> <title>jQuery Bind onclick Event to Dynamically added Elements</title> <script type="text/javascript" src="http://code.jquery.com/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("ol").append("<li>list item <a href='javascript:void(0);' class='remove'>&times;</a></li>"); }); $(document).on("click", "a.remove" , function() { $(this).parent().remove(); }); }); </script> </head> <body> <button>Add new list item</button> <p>Click the above button to dynamically add new list items. You can remove it later.</p> <ol> <li>list item</li> <li>list item</li> <li>list item</li> </ol> </body> </html>

Mysql Query to toggle int value


Hey.. want to toggle a field value from 0 to 1 or 1 to 0 in single query..

There are Several Method



UPDATE `tbl1` SET clmn = clmn XOR 1

UPDATE `tbl1` SET clmn = 1 - clmn



UPDATE tbl1   SET `status` = !`status`






Advertisement

Tuesday, June 23, 2015

Pagination with Jquery and PHP

<?php
$pageNumber=$_REQUEST['page'];
$pageFrom=($pageNumber==1?0:($p_value*10-10));
$pageLimit=($pageNumber==1?10:($p_value*10+10));

$data=array_slice($all_data, $pageFrom, $pageLimit );
 foreach($data as $key => $value){

    // your code goes here..
}

?>

Note-: Your all row should be save in array. this code will just slice all record into 10-10 pieces..


Want more help-: contact me on facebook.com/sudhir600