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;

?>