Welcome to Onlinetunes24 .....

We are committed to become your long-term, trusted partner. Our priority is not only to provide professional services and solutions but to become your IT vendor dedicated to meet your needs today and support your growing business needs tomorrow.

This is default featured post 1 title

We are committed to become your long-term, trusted partner. Our priority is not only to provide professional services and solutions but to become your IT vendor dedicated to meet your needs today and support your growing business needs tomorrow.

This is default featured post 2 title

We are committed to become your long-term, trusted partner. Our priority is not only to provide professional services and solutions but to become your IT vendor dedicated to meet your needs today and support your growing business needs tomorrow.

This is default featured post 3 title

We are committed to become your long-term, trusted partner. Our priority is not only to provide professional services and solutions but to become your IT vendor dedicated to meet your needs today and support your growing business needs tomorrow.

This is default featured post 4 title

We are committed to become your long-term, trusted partner. Our priority is not only to provide professional services and solutions but to become your IT vendor dedicated to meet your needs today and support your growing business needs tomorrow.

Showing posts with label ওয়েব প্রোগ্রামিং (Web Programming). Show all posts
Showing posts with label ওয়েব প্রোগ্রামিং (Web Programming). Show all posts

Bubble sort algorithm is a basic algorithm for sorting sets of numbers. It is the one you will probably be confronted with at college. There are probably better sorting algorithms but since this is the one you will most likely encounter, I have decided to write a simple implementation of it in PHP.

The idea is simple. You iterate over an array (from the first to the last but one number) using a while loop until it’s sorted. In every iteration you compare the current and the next number. If the current number is greater than the next number, switch them. That’s in a case you want to sort the array in ascending order. For descending order it is very similar. Just change < to >.

Source Code:
<?php
    // Ascending order function
    function bubbleSortAsc(array $arr)
    {
        $sorted = FALSE;
        while ($sorted === FALSE)
        {
            $sorted = TRUE;
            for ($i = 0; $i < count($arr)-1; ++$i)
            {
                $current = $arr[$i];
                $next = $arr[$i+1];
                if ($next < $current)
                {
                    $arr[$i] = $next;
                    $arr[$i+1] = $current;
                    $sorted = FALSE;
                }
            }
        }
        return $arr;
    }
   
    // Descending order function
    function bubbleSortDesc(array $arr)
    {
        $sorted = FALSE;
        while ($sorted === FALSE)
        {
            $sorted = TRUE;
            for ($i = 0; $i < count($arr)-1; ++$i)
            {
                $current = $arr[$i];
                $next = $arr[$i+1];
                if ($next > $current)
                {
                    $arr[$i] = $next;
                    $arr[$i+1] = $current;
                    $sorted = FALSE;
                }
            }
        }
        return $arr;
    }
   
   
    // Call any function
    $arr_val = array(50, 1, 45, 10, 40, 20, 35, 30, 3, 2);
    $sortedArr = bubbleSortAsc($arr_val);
    print_r($sortedArr);
?>

Compare Date Month Year etc.

// Find Today
    function today()
    {
        return date('Y-m-d');
    }


// Find Yesterday   
    function yesterday()
    {
        return date("Y-m-d", strtotime("yesterday"));
    }
 

// Find Current Week   
    function currentweek()
    {
        return date('Y-m-d'). ' To ' .date('Y-m-d', strtotime('-7 days'));
    }
 

// Find Last Week   
    function lastweek()
    {
        return date('Y-m-d', strtotime('-7 days')). ' To ' . date('Y-m-d', strtotime('-13 days'));
    }
 

// Find Current Month   
    function currentmonth()
    {
        return date('Y-m');
    }
 

// Find Last Month   
    function lastmonth()
    {
        return date("Y-m", strtotime("previous month"));
    }
 

// Find Current Year   
    function currentyear()
    {
        return date("Y");
    }
 

// Find Last Year   
    function lastyear()
    {
        return date("Y", strtotime("last year"));
    }

Encrypted and Decrypted using md5

<?php
 

echo 'Input = '.$input ="Admin".'<br>';

$encrypted = encryptIt( $input );
$decrypted = decryptIt( $encrypted );

echo 'Encrypted = '.$encrypted . '<br />' .'Decrypted = '.$decrypted;

function encryptIt( $q ) {
    $cryptKey  = 'qJB0rGtIn5UB1xG03efyCp';
    $qEncoded      = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), $q, MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ) );
    return( $qEncoded );
}

function decryptIt( $q ) {
    $cryptKey  = 'qJB0rGtIn5UB1xG03efyCp';
    $qDecoded      = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $q ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "\0");
    return( $qDecoded );
}


?>

Find the root of equation: X^2-2X-3 = 0. using iterative method. Take initial value X = 2

Find the root of equation: X2-2X-3 = 0. using iterative method. Take initial value X = 2 [Calculation up to 4 decimal places]

Program:
<?php
    $c = 2; // Counter Start Value Assign Here.
    $x = "";
    $x2 = 2;    // Initial value Assign Here.
   
    echo "X 1 = 2 <br />"; // Assign X1 Value Here.
   
    for ($i = 2; $i <= $c; $i = $i+1)    {
        $x=$x2;
        // Simplify Equation Here.
        $x2 = number_format(sqrt((2*$x)+3),"4",".","");
        $c++;    // Increment Counter Value.
        echo "X $i = " .$x2 . '<br />';

        if ($x === $x2) {
            echo "<h3 style = 'color:green'> Hello same value $x2 is found. </h3>";
            $c = $i-1;
        }
    }
?>

Find the root of equation: x-cosx = 0. using iterative method. Take initial value X = 1

Find the root of equation: x-cosx = 0. using iterative method. Take initial value X = 1 [Calculation up to 4 decimal places]

Program:
 <?php
    $c = 2; // Counter Start Value Assign Here.
    $x = "";
    $x2 = 1;    // Initial value Assign Here.
   
    echo "X 1 = 1 <br />"; // Assign X1 Value Here.
   
    for ($i = 2; $i <= $c; $i = $i+1)    {
        $x=$x2;
        // Simplify Equation Here.
        $x2 = number_format((cos($x)),"4",".","");
        $c++;    // Increment Counter Value.
        echo "X $i = " .$x2 . '<br />';

        if ($x === $x2) {
            echo "<h3 style = 'color:green'> Hello same value $x2 is found. </h3>";
            $c = $i-1;
        }
    }
?>

Consider the quadratic equation: X^2-2X-2 = 0. Find the root of this equation using iterative method. Take initial value X1 = 1

Consider the quadratic equation: X2-2X-2 = 0. Find the root of this equation using iterative method. Take initial value X1 = 1 [Calculation up to 3 decimal places]

Program:
<?php
    $c = 2; // Counter Start Value Assign Here.
    $x = "";
    $x2 = 1;    // Initial value Assign Here.
   
    echo "X 1 = 1 <br />"; // Assign X1 Value Here.
   
    for ($i = 2; $i <= $c; $i = $i+1)    {
        $x=$x2;
        // Simplify Equation Here.
        $x2 = number_format((1-(0.5*($x*$x))),"3",".","");
        $c++;    // Increment Counter Value.
        echo "X $i = " .$x2 . '<br />';

        if ($x === $x2) {
            echo "<h3 style = 'color:green'> Hello same value $x2 is found. </h3>";
            $c = $i-1;
        }
    }
?>

Find the root of given eqution using iterative method.

Consider the quadratic equation: 2X2-4X+1 = 0. Find the root of this equation using iterative method. Take initial value x=1 [Calculation up to 4 decimal places]

Program:

<?php
    $c = 2; // Counter Start Value Assign Here.
    $x = "";
    $x2 = 1;    // Initial value Assign Here.
   
    echo "X 1 = 1 <br />"; // Assign X1 Value Here.
   
    for ($i = 2; $i <= $c; $i = $i+1)    {
        $x=$x2;
        // Simplify Equation Here.
        $x2 = number_format(((0.5*($x*$x))+(1/4)),"4",".","");
        $c++;    // Increment Counter Value.
        echo "X $i = " .$x2 . '<br />';

        if ($x === $x2) {
            echo "<h3 style = 'color:green'> Hello same value $x2 is found. </h3>";
            $c = $i-1;
        }
    }
?>

Convert numbers into strings

Here is a simple function to convert numbers into strings like this:
0 => 0000
1 => 0001
20 => 0020
432 => 0432

<?php
 
function number_pad($number,$n) {
    return
str_pad((int) $number,$n,"0",STR_PAD_LEFT);
  }
?>
$n indicates how many characters you want.

// optional  $number = 0; for ($i=1; $i<=50; $i=$i+1){
    $number = $number+$i;
    echo str_pad($number, 5, "0", STR_PAD_LEFT) . '<br />' ;
}
?>

How to convert mysql date format to user define php date format.

User define PHP date format to MySQL date format.
echo 'Orginal = ' . $date = '06/03/2014';
echo ' To ' . $date = date("Y-m-d", strtotime($date)) .'<br />' ;

MySQL date format to User define PHP date format.
echo 'Orginal2 = ' . $date2 = '2014-03-06';
echo ' To ' . $date2 = date ('d-m-Y', strtotime($date2)) .'<br />' ;

Remove file extention from URL

আমি আপনাদের দেখাবো কিভাবে আপনি আপনার সাইট এর ইউ আর এল এক্সটেনশন থেকে .html , .php , .aspx ইত্যাদি রিমুভ করবেন।

প্রথমে আপনার কন্ট্রোল প্যানেল এ লগিন করুণ তার পর আপনার ফাইল ম্যানেজার এ প্রবেশ করুণ । ওখানে দেখুন .htaccess নামে একটি ফাইল আছে , এখন আপনি এই ফাইল টিতে ক্লিক করে এডিট বাটন চাপুন এডিটর এ ফাইল টি ওপেন হলে এই কোড টুকু জুড়ে দিন

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteRule ^([^\.]+)$ $1.php [NC,L] 

এখানে খেয়াল করুণ $1 এর পরে .পিএইচপি আছে আপনার ফাইল টি যদি পিএইচপি হয় তাহলে এটা বদলানুর দরকার নেই ,
যদি আপনার ফাইল টি এইচটিএমএল ফাইল হয় তাহলে আপনি $1 এর পরে .পিএইচপি লেখাটি বাদ দিয়ে .এইচটিএমএল লিখে দিবেন , 
যদি আপনার ফাইল টি aspx ফাইল হয় তাহলে আপনি $1 এর পরে .পিএইচপি লেখাটি বাদ দিয়ে .aspx লিখে দিবেন।

লিখা শেষ হলে আপনার ফাইলটি কে সেভ দিয়ে ক্লোজ করে দিবেন তাহলেই হয়ে যাবে।
আর আপনি যখন আপনার ফাইল টি কে লিঙ্ক করাবেন তখন আপনাকে আর ফাইল এর এক্সটেনশন দিতে হবে না।

এম.ভি.সি


এমভিসি বা মডেল-ভিউ-কন্ট্রোলার খুবই জনপ্রিয় একটি প্যাটার্ন । Trygve Reenskaug নামের এক ভদ্রলোক এই প্যাটার্নটির জনক। এমভিসি প্যাটার্নের মূল বক্তব্য হলো এই প্যাটার্নে তিনটি কম্পোনেন্ট থাকবে – একটি মডেল যেটি ডাটা নিয়ে কাজ করবে, একটি ভিউ যেটার কাজ হবে মডেলকে ভিজ্যুয়ালাইজ করা এবং একটি কন্ট্রোলার যেটি ব্যবহারকারী এবং সিস্টেমের মধ্য সমন্বয়কারী হিসেবে কাজ করে । 

আমরা যদি এমভিসি কম্পোনেন্টগুলোর দিকে নজর দেই তাহলে দেখবো – 

মডেল: মডেলের কাজই হলো ডাটা নিয়ে কাজ করা । মডেল হতে পারে একটি অবজেক্ট কিংবা অনেকগুলো অবজেক্ট এর একটি স্ট্রাকচার । একটি সিস্টেমের সব ধরণের নলেজ বা ডাটা মডেল দিয়ে রিপ্রেজেন্ট করা যায় । ক্ষেত্রবিশেষে মডেল তার অবস্থা পরিবর্তন হলে (যেমন: কোন ভ্যালুর মান পাল্টে গেলে) কন্ট্রোলার বা ভিউকে নোটিফাই করে যাতে প্রয়োজনীয় প্রসেসিং করা সম্ভব হয় । ওয়েবে সাধারণত এ ধরণের নোটিফিকেশন এর সুযোগ থাকে না । 

ভিউ: ভিউ এর কাজ হচ্ছে মডেলকে ব্যবহারকারীর সামনে তুলে ধরা । সাধারণত ভিউ মডেল থেকে ডাটা নিয়ে সেটাকে ব্যবহারকারীর কাছে সহজবোধ্য রূপে তুলে ধরে । 

কন্ট্রোলার: কন্ট্রোলার ব্যবহারকারীর কাছ থেকে তথ্য সংগ্রহ করে আবার ব্যবহারকারীর প্রয়োজনমত ভিউ উপস্থাপন করে । কন্ট্রোলারই বলে দেয় ভিউ কোন মডেল থেকে ডাটা নিয়ে কিভাবে উপস্থাপন করবে । এছাড়াও কন্ট্রোলার মডেলে নানা ধরণের পরিবর্তন করতে পারে প্রয়োজনমত । 

আমরা যদি জনপ্রিয় পিএইচপি ফ্রেমওয়ার্ক চিন্তা করি তাহলে দেখবো – 

# মডেল অবজেক্টগুলো সরাসরি ডাটাবেইজের টেবিলকে রিপ্রেজেন্ট করে । একেকটি মডেল ব্যবহার করে আমরা একেক টেবিল থেকে ডাটা এ্যাক্সেস করতে পারি ।

# ভিউ থাকে এইচটিএমএল এর মত বিশেষ টেম্প্লেট যেটা জানে কিভাবে এইচটিএমএল কোড আউটপুট করতে হবে ।

# কন্ট্রোলার অবজেক্টগুলো ব্যবহারকারীর ইচ্ছামত প্রয়োজনীয় মডেল থেকে ডাটা এনে ভিউ তৈরি করে দেয় । 

কি করে বুঝবেন যে আপনার এ্যাপ্লিকেশনটি সঠিকভাবে এমভিসি প্যাটার্ন অনুসরণ করছে? নিজেকে জিজ্ঞাসা করুন এই এ্যাপ্লিকেশনটি থীমেবল কিনা । অর্থাৎ চাইলেই আপনি এটির জন্য অনেকগুলো থীম তৈরি করে ডাইনামিকালি থীম পরিবর্তন করতে পারছেন কিনা । যদি সেটা সম্ভব হয় তবে সম্ভবত আপনি সঠিকভাবেই এমভিসি ফলো করেছেন আর যদি সম্ভব না হয় তবে আপনি এমভিসি কম্পোনেন্টগুলোকে আলাদা করতে পারেননি ঠিকমতো ।

In word unicode function

File : inword_unicode_function.php 

<?php
    // taka in word function
     function convertNumberToWords($number){
        //A function to convert numbers into bangladesh readable words with Cores, Lakhs and Thousands.
        $words = array('0'=>'','1'=>'এক','2'=>'দুই','3'=>'তিন','4'=>'চার','5'=>'পাঁচ','6'=> 'ছয়','7'=>'সাত','8'=>'আট','9'=>'নয়','10'=>'দশ','11'=>'এগার','12'=>'বার','13'=>'তের','14'=>'চৌদ্দ','15'=>'পনের','16'=>'ষোল','17'=>'সতের','18'=>'আঠার','19'=>'ঊনিশ','20'=>'বিশ','21'=>'একুশ','22'=>'বাইশ','23'=>'তেইশ','24'=>'চব্বিশ','25'=>'পঁচিশ',
            '26'=>'ছাব্বিশ','27'=>'সাতাশ','28'=>'আঠাশ','29'=>'ঊনত্রিশ','30'=>'ত্রিশ','31'=>'একত্রিশ','32'=>'বত্রিশ','33'=>'তেত্রিশ','34'=>'চৌত্রিশ','35'=>'পয়ত্রিশ','36'=>'ছত্রিশ','37'=>'সাইত্রিশ','38'=>'আটত্রিশ','39'=>'ঊনচল্লিশ','40'=>'চল্লিশ','41'=>'একচল্লিশ','42'=>'বিয়াল্লিশ','43'=>'তিতাল্লিশ','44'=>'চুয়াল্লিশ','45'=>'পয়তাল্লিশ','46'=>'ছেচল্লিশ','47'=>'সাতচল্লিশ','48'=>'আটচল্লিশ','49'=>'ঊনপঞ্ঝাশ','50'=>'পঞ্ঝাশ',
            '51'=>'একান্ন','52'=>'বায়ান্ন','53'=>'তিপ্পান্ন','54'=>'চুয়ান্ন','55'=>'পঞ্ঝান্ন','56'=>'ছাপ্পান্ন','57'=>'সাতান্ন','58'=>'আটান্ন','59'=>'ঊনষাট','60'=>'ষাট ','61'=>'একষট্রি','62'=>'বাষট্রি','63'=>'তেষট্রি','64'=>'চৌষট্রি','65'=>'পয়ষট্রি','66'=>'ছেষট্রি','67'=>'সাতষট্রি','68'=>'আটষট্রি','69'=>'ঊনসত্তর','70'=>'সত্তর','71'=>'একাত্তর','72'=>'বায়াত্তর','73'=>'তেয়াত্তর','74'=>'চুয়াত্তর','75'=>'পচাত্তর',
            '76'=>'ছিয়াত্তর','77'=>'সাতাত্তর','78'=>'আটাত্তর','79'=>'ঊনআশি','80'=>'আশি','81'=>'একাশি','82'=>'বিরাশি ','83'=>'তিরাশি','84'=>'চুরাশি','85'=>'পঁচাশি','86'=>'ছিয়াশি','87'=>'সাতাশি','88'=>'আটাশি','89'=>'ঊননব্বই','90'=>'নব্বই','91'=>'একানব্বই','92'=>'বিরানব্বই','93'=>'তিরানব্বই','94'=>'চুরানব্বই','95'=>'পচানব্বই','96'=>'ছিয়ানব্বই','97'=>'সাতানব্বই','98'=>'আটানব্বই','99'=>'নিরানব্বই');
        //First find the length of the number
        $number_length = strlen($number);
        //Initialize an empty array
        $number_array = array(0,0,0,0,0,0,0,0,0);      
        $received_number_array = array();
        //Store all received numbers into an array
        for($i=0;$i<$number_length;$i++){   
            $received_number_array[$i] = substr($number,$i,1);}
        //Populate the empty array with the numbers received - most critical operation
        for($i=9-$number_length,$j=0;$i<9;$i++,$j++){
            $number_array[$i] = $received_number_array[$j];}
        $number_to_words_string = "";      
        //Finding out whether it is teen, tweenty......ninety
        for($i=0,$j=1;$i<9;$i++,$j++){
            if($i==0 || $i==2 || $i==4 || $i==7){
                if($number_array[$i]=="1"){
                    $number_array[$j] = 10+$number_array[$j];
                    $number_array[$i] = 0;} 
                if($number_array[$i]=="2"){
                    $number_array[$j] = 20+$number_array[$j];
                    $number_array[$i] = 0;}
                if($number_array[$i]=="3"){
                    $number_array[$j] = 30+$number_array[$j];
                    $number_array[$i] = 0;}
                if($number_array[$i]=="4"){
                    $number_array[$j] = 40+$number_array[$j];
                    $number_array[$i] = 0;}
                if($number_array[$i]=="5"){
                    $number_array[$j] = 50+$number_array[$j];
                    $number_array[$i] = 0;}
                if($number_array[$i]=="6"){
                    $number_array[$j] = 60+$number_array[$j];
                    $number_array[$i] = 0;}
                if($number_array[$i]=="7"){
                    $number_array[$j] = 70+$number_array[$j];
                    $number_array[$i] = 0;}
                if($number_array[$i]=="8"){
                    $number_array[$j] = 80+$number_array[$j];
                    $number_array[$i] = 0;}
                if($number_array[$i]=="9"){
                    $number_array[$j] = 90+$number_array[$j];
                    $number_array[$i] = 0;}
            }
        }
        $value = "";
        for($i=0;$i<9;$i++){
            if($i==0 || $i==2 || $i==4 || $i==7){
                $value = $number_array[$i]*10;}
            else{
                $value = $number_array[$i];}          
            if($value!=0){       
                $number_to_words_string.= $words["$value"]." ";}
            if($i==1 && $value!=0){       
                $number_to_words_string.= "কোটি ";}
            if($i==3 && $value!=0){       
                $number_to_words_string.= "লক্ষ ";}
            if($i==5 && $value!=0){       
                $number_to_words_string.= "হাজার ";}
            if($i==6 && $value!=0){       
                $number_to_words_string.= "শত ";}
        }
        if($number_length>9){
            $number_to_words_string = '<span style="color:red">'."দুঃখিত এই ফাংশনটি ৯৯ কোটির উপরে সাপোর্ট করে না।".'</span>';}
        return ucwords(strtolower('কথায়ঃ '.$number_to_words_string)."টাকা মাত্র");
    }
?>








File : main.php
<!DOCTYPE>
<html>
<head>
    <meta charset="utf-8">
    <title>বাংলা</title>
</head>
<body>
<form action="" method="post">
Value : <input name="n" value="" />
</form>
    <?php
        echo $number = $_POST['n'];
        echo '<br />';
        echo $str = convertNumberToWords(round($number),0);
    ?>
</body>
</html>

In word function

<?php
// taka in word function
     function convertNumberToWordsForIndia($number){
        //A function to convert numbers into Bangladesh readable words with Cores, Lakhs and Thousands.
        $words = array(
        '0'=> '' ,'1'=> 'one' ,'2'=> 'two' ,'3' => 'three','4' => 'four','5' => 'five',
        '6' => 'six','7' => 'seven','8' => 'eight','9' => 'nine','10' => 'ten',
        '11' => 'eleven','12' => 'twelve','13' => 'thirteen','14' => 'fouteen','15' => 'fifteen',
        '16' => 'sixteen','17' => 'seventeen','18' => 'eighteen','19' => 'nineteen','20' => 'twenty',
        '30' => 'thirty','40' => 'fourty','50' => 'fifty','60' => 'sixty','70' => 'seventy',
        '80' => 'eighty','90' => 'ninty');
      
        //First find the length of the number
        $number_length = strlen($number);
        //Initialize an empty array
        $number_array = array(0,0,0,0,0,0,0,0,0);      
        $received_number_array = array();
      
        //Store all received numbers into an array
        for($i=0;$i<$number_length;$i++){    $received_number_array[$i] = substr($number,$i,1);    }

        //Populate the empty array with the numbers received - most critical operation
        for($i=9-$number_length,$j=0;$i<9;$i++,$j++){ $number_array[$i] = $received_number_array[$j]; }
        $number_to_words_string = "";      
        //Finding out whether it is teen ? and then multiplying by 10, example 17 is seventeen, so if 1 is preceeded with 7 multiply 1 by 10 and add 7 to it.
        for($i=0,$j=1;$i<9;$i++,$j++){
            if($i==0 || $i==2 || $i==4 || $i==7){
                if($number_array[$i]=="1"){
                    $number_array[$j] = 10+$number_array[$j];
                    $number_array[$i] = 0;
                }      
            }
        }
      
        $value = "";
        for($i=0;$i<9;$i++){
            if($i==0 || $i==2 || $i==4 || $i==7){    $value = $number_array[$i]*10; }
            else{ $value = $number_array[$i];    }          
            if($value!=0){ $number_to_words_string.= $words["$value"]." "; }
            if($i==1 && $value!=0){    $number_to_words_string.= "Crores "; }
            if($i==3 && $value!=0){    $number_to_words_string.= "Lakhs ";    }
            if($i==5 && $value!=0){    $number_to_words_string.= "Thousand "; }
            if($i==6 && $value!=0){    $number_to_words_string.= "Hundred "; }
        }
        if($number_length>9){ $number_to_words_string = "Sorry This does not support more than 99 Crores"; }
        return ucwords(strtolower("In words : ".$number_to_words_string)." Taka Only.");
    }
    echo convertNumberToWordsForIndia("3950");
?>

Multi row inserting

Page.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Page 1</title>
</head>

<body>
<?php
    if (isset($_POST['go'])){
        echo "Date : " .$date = date('d-m-Y');
        $number = $_POST['number'];
        echo "<br/> Member : ".$number;
        echo '<table border="1" align="center" cellpadding="5"><tr> <th>ID</th> <th>Name of Member</th> <th>Cell No</th> </tr>';
        echo '<form name="addmember" method="post" action="script.php">';
        for ($i=1; $i<=$number; $i++){
            ?>
            <tr>
                <td>Member (<?php echo $i ?>) </td>
                <td><input type="text" name="name[]" value="" /></td>
                <td><input type="text" name="cell[]" value="" /></td>
                <input type="hidden" name="number" value="<?php echo $number; ?>" />
            </tr>
            <?php }
       
        echo '<tr align="right"> <td colspan="3">';
            echo '<input type="submit" name="submit" value="Save" />';   
            //echo '<input type="submit" name="back" value="Back" />';
        echo '</td></tr>';
        echo '</form>';
        }
       
    else{
        ?>
        <form name="menber" method="post">
            Number of Member : <input type="text" name="number" value="" />
            <input type="submit" name="go" value="Go" />
        </form>
        <?php }
?>
</body>
</html>


Script.php
<?php
    $host = 'localhost';
    $username = 'root';
    $password = '';
    $database = 'test';
   
    $con = mysql_connect($host, $username, $password) or die (mysql_error("Database connecton error !!"));
    mysql_select_db($database, $con) or die (mysql_error("Database Selection error !!"));
   
    $date = date('d-m-Y');
    $total = $_POST['number'];
    $name = $_POST['name'];
    $cell = $_POST['cell'];

    for ($i=0; $i<$total; $i++){
        mysql_query ("insert into machmember values (null, '".$name[$i]."', '".$cell[$i]."', '".$date."')");
        }
        echo "Data insert succesfully !!";
?>

PHP Mysql Diagram

Create database and table: 
-- Database: `test`
--
-- --------------------------------------------------------
--
-- Table structure for table `graph`
--

CREATE TABLE IF NOT EXISTS `graph` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `month` varchar(255) NOT NULL,
  `amount` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=13 ;

--
-- Dumping data for table `graph`
--

INSERT INTO `graph` (`id`, `month`, `amount`) VALUES
(1, 'January', '1000'),
(2, 'February', '1500'),
(3, 'March', '1200'),
(4, 'April', '2000'),
(5, 'May', '2500'),
(6, 'June', '1500'),
(7, 'July', '1000'),
(8, 'August', '2500'),
(9, 'September', '4000'),
(10, 'October', '2500'),
(11, 'November', '1000'),
(12, 'December', '3000');


Diagram.php: 
<?php
$host="localhost";
$user="root";
$pass="";
$database="test";

$con=mysql_connect($host, $user, $pass) or die ("MySQL Database Select ERROR()");
mysql_select_db("$database", $con);
?>
<html>
<head>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<TITLE>Make Line Charts from MySQL Table Data</TITLE>
<meta name="description" content="Make Line Charts from MySQL Table Data">
<meta name="keywords" content="Make Line Charts from MySQL Table Data,View MySQL Table Data as Line Charts,chart MySQL Table Data,php,javascript, dhtml, DHTML">

<STYLE TYPE="text/css">
    BODY {margin-left:0; margin-right:0; margin-top:0;text-align:left;}
    p, li, td {font:13px Verdana; color:black;text-align:left}
    h1 {font:bold 28px Verdana; color:black;text-align:center}
    h2 {font:bold 24px Verdana;text-align:center}
    h3 {font:bold 15px Verdana;}
    #myid {position:absolute;left:10px;top:117px;height:380px;border: solid 1px #000;}
    #myform {position:absolute;left:50px;top:20px}
    #label {position:absolute;left:400px;top:550px;}
    .bDiv {
    width: 76px;
    border: none;
    background-color: transparent;
    font-size: 11px;
    font-weight: bold;
    font-family: verdana;
    color: #000;
    padding: 5px;
    overflow:hidden
    }
</STYLE>
</head>

<body>

<div id='myform'>
<center><h1>Make Line Charts from MySQL Table Data</h1></center>
<form action='diagram.php' method='post' name='sendname'>
<center><input type='text' name='table' id='whattable' size='35' maxlength='40' value=''>
<input type='submit' value='Get chart data' name='flag'></center></form></div>

<?php
$month=array();$amount=array();
$table=$_POST['table'];$t=$table;
if(strlen($table) > 0){
$exists = mysql_query("SHOW TABLES LIKE '$table'") or die(mysql_error());
$num_rows = mysql_num_rows($exists);
if($num_rows>0){
$sql=mysql_query("SELECT * FROM $table");
if(mysql_num_rows($sql)>0){
unset($table);

while($row = mysql_fetch_array($sql)){
$m=htmlentities(stripslashes($row['month']), ENT_QUOTES);
$a=htmlentities(stripslashes($row['amount']), ENT_QUOTES);
array_push ($amount, $a);
array_push ($month, $m);
}
$biggest=max($amount);

mysql_close();}}
else{echo '<script language="javascript">alert("No such table.");window.location="diagram.php";</script>;';}
}
?>

<script language="javascript">
var xa, xb, ya, yb, x, y; var addtopage = "";

function goodline(xa, xb, ya, yb) {
var lengthofline = Math.sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
for(var i=0; i<lengthofline; i++){
x=Math.round(xa+(xb-xa)*i/lengthofline);
y=Math.round(ya+(yb-ya)*i/lengthofline);
addtopage += "<div style='position:absolute;left:"+x+"px;top:"+y+"px;background-color:#a4a4a4;width:4px;height:4px;font-size:1px'></div>";}
addtopage += "<div style='position:absolute;left:"+xx[q]+"px;top:117px;'><IMG SRC='vert.gif' WIDTH=2 HEIGHT=380 BORDER=0></div>";
document.body.innerHTML += addtopage;}

var m = <?php echo json_encode($month); ?>;
var a = <?php echo json_encode($amount); ?>;
var b = <?php echo json_encode($biggest); ?>;
var t = <?php echo json_encode($t); ?>;
var r=b/350;var xx = new Array();var yy = new Array();
var ll=(b.toString()).length;
var factor=Math.pow(10,-1*(ll-1));
var num=(Math.floor(b*factor)/factor);
var fac=Math.pow(10,ll-1);
var firstint=num/fac;
var dd=num/b;
var o=Math.round((350*dd)/firstint); //497y start then go up (y less) for each tic
for (var i=firstint;i>0;i--){
var divTag = document.createElement("div");
divTag.id="a" + i;
divTag.style.marginLeft = 10+"px";
divTag.style.position = "absolute";
divTag.style.top = (497-o*(firstint-(firstint-i)))+"px";
divTag.style.height = 2+"px";
divTag.innerHTML = "<IMG SRC='hor.gif' WIDTH='"+(a.length*80)+"' HEIGHT='2' BORDER='0'>";
document.body.appendChild(divTag);
}

if (a.length > 0 && m.length > 0) {

for (var i=0;i<a.length;i++){q=i;
xx[i]=i*78+59;
yy[i]=497-(a[i]/r);
if(i>0){goodline(xx[i-1], xx[i], yy[i-1], yy[i]);}else{addtopage += "<div style='position:absolute;left:"+xx[q]+"px;top:117px;'><IMG SRC='vert.gif' WIDTH=2 HEIGHT=380 BORDER=0></div>";}
}

for (var i=0;i<a.length;i++){
var divTag = document.createElement("div");
divTag.id="b" + i;
divTag.setAttribute("align", "center");
divTag.style.marginLeft = (i*78+20)+"px";
divTag.style.position = "absolute";
divTag.style.top = 500+"px";
divTag.style.height = 22+"px";
divTag.className = "bDiv";
divTag.innerHTML = m[i];
document.body.appendChild(divTag);
}

for (var i=0;i<a.length;i++){
var divTag = document.createElement("div");
divTag.id="c" + i;
divTag.setAttribute("align", "center");
divTag.style.marginLeft = (i*78+20)+"px";
divTag.style.position = "absolute";
divTag.style.top = (470-(a[i]/r))+"px";
divTag.style.height = 22+"px";
divTag.className = "bDiv";
divTag.innerHTML = a[i];
document.body.appendChild(divTag);
}
document.write("<div id='label'><h1>"+t+"</h1></div><div id='myid' style='min-width:"+(a.length*80)+"px; width:"+(a.length*80)+"px'> </div>");
}
</script>

</body>
</html>

Database backup 2 mail

<?php
$db_host="localhost";   //mysql host 
$db_user="xxxxx";  //databse user name
$db_pass="xxxxx";  //database password
$db_name="xxxxx";  //database name
$tables="*";   // use * for all tables or use , to seperate table names
$email="me@mail.com";     //your email id
///////////////////////////////////////////////////////////////////////////////////////////

/////////don't need to change bellow //////

backup($db_host,$db_user,$db_pass,$db_name,$tables,$email);
function backup($db_host,$db_user,$db_pass,$db_name,$tables = '*',$email)
{

  $con= mysql_connect($db_host,$db_user,$db_pass);
  mysql_select_db($db_name,$con);

  //get all of the tables
  if($tables == '*')
  {
    $tables = array();
    $result = mysql_query('SHOW TABLES');
    while($row = mysql_fetch_row($result))
    {
      $tables[] = $row[0];
    }
  }
  else
  {
    $tables = is_array($tables) ? $tables : explode(',',$tables);
  }

  //cycle through
  foreach($tables as $table)
  {
    $result = mysql_query('SELECT * FROM '.$table);
    $num_fields = mysql_num_fields($result);

    $return.= 'DROP TABLE '.$table.';';
    $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
    $return.= "\n\n".$row2[1].";\n\n";

    for ($i = 0; $i < $num_fields; $i++)
    {
      while($row = mysql_fetch_row($result))
      {
        $return.= 'INSERT INTO '.$table.' VALUES(';
        for($j=0; $j<$num_fields; $j++)
        {
          $row[$j] = addslashes($row[$j]);
          $row[$j] = ereg_replace("\n","\\n",$row[$j]);
          if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
          if ($j<($num_fields-1)) { $return.= ','; }
        }
        $return.= ");\n";
      }
    }
    $return.="\n\n\n";
  }

  //save file
  $filename='db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql';
  $handle = fopen($filename,'w+');
  fwrite($handle,$return);
  fclose($handle);
  compress($filename);
  send_mail($filename.".zip",$email);
}

function send_mail($filepath,$email)
{

$from = "Backup <you@yourdomain.com>";
$subject = "Database backup";
$message="This attachment contains the backup of your database.";
$separator = md5(time());

// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;

// attachment name
$filename = "backup".date('d-m-Y').".zip";

//$pdfdoc is PDF generated by FPDF
$attachment = chunk_split(base64_encode(file_get_contents($filepath)));

// main header
$headers  = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";

// no more headers after this, we start the body! //

$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "This is a MIME encoded message.".$eol;

// message
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol;

// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";

// send message
if (mail($email, $subject, $body, $headers)) {
    echo "Your backup sent to your email id";
    header("refresh: 1; main.php");
} else {
    echo "Oops mail can not be send";
}
}
function compress($filepath)

     {

         $zip = new ZipArchive();
  $file=$filepath.".zip";
 if($zip->open($file,1?ZIPARCHIVE::OVERWRITE:ZIPARCHIVE::CREATE)===TRUE)
 {
   // Add the files to the .zip file
   $zip->addFile($filepath);

   // Closing the zip file
   $zip->close();
 }
     }

Unicode Convert Function

<?php
    class bn_en {
        public function bnen($val){
            $en = array ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
            $bn = array ( '০', '১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯');
            return str_ireplace($bn, $en, $val);
        }
        public function enbn($val){
            $en = array ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
            $bn = array ( '০', '১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯');
            return str_ireplace($en, $bn, $val);
        }
    }
?>
<!DOCTYPE>
<html>
<head>
<meta charset="utf-8">
<title>বাংলা</title>
</head>
<body>
<?php
// input
$val1='১০';
$val2='২৫';
$bninput = new bn_en();
echo $out = $bninput->bnen($val1)+$bninput->bnen($val2);
echo '<br />';
// output
$bnoutput = new bn_en();
echo $bnoutput->enbn($out);

?>
</body>
</html>

Show Bangla Date Time

<?php
class ShowBanglaDateTime{
//Base function
    public function bangla_date_time($str){
$eng = array('January','February','March','April','May','June','July','August','September','October','November','December',
'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec',
'Saturday','Sunday','Monday','Tuesday','Wednesday','Thursday','Friday',
'Sat','Sun','Mon','Tue','Wed','Thu','Fri',
'1','2','3','4','5','6','7','8','9','0',
'am','pm');
$bng = array('জানুয়ারি','ফেব্রুয়ারি','মার্চ','এপ্রিল','মে','জুন','জুলাই','আগস্ট','সেপ্টেম্বর','অক্টোবর','নভেম্বর','ডিসেম্বর',
'জানু','ফেব্রু','মার্চ','এপ্রি','মে','জুন','জুলা','আগ','সেপ্টে','অক্টো','নভে','ডিসে',
'শনিবার','রবিবার','সোমবার','মঙ্গলবার','বুধবার','বৃহস্পতিবার','শুক্রবার',
'শনি','রবি','সোম','মঙ্গল','বুধ','বৃহঃ','শুক্র',
'১','২','৩','৪','৫','৬','৭','৮','৯','০',
'পূর্বাহ্ণ','অপরাহ্ণ');
return str_ireplace($eng, $bng, $str);
}
}
?>
<!DOCTYPE>
<html>
<head>
<meta charset="utf-8">
<title>বাংলাতে সময় ও তারিখ</title>
</head>
<body>
<?php
date_default_timezone_set('Asia/Dhaka');
$BanglaDate=new ShowBanglaDateTime();
echo $BanglaDate->bangla_date_time(date('d M Y h:i A'));
?>
</body>
</html>

PHP Email with an attach file

<?php
    if(isset($_POST['submit'])) {
        //Deal with the email
        $to = "engr.lukman@gmail.com";
        $name = $_POST['name'];
        $email = $_POST['email'];
        $subject = $_POST['subject'];
       
        $message = strip_tags($_POST['message']);
        $attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
        $filename = $_FILES['file']['name'];
        $boundary =md5(date('r', time()));
        $headers = "From:" .$name." : ".$email;
        $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";
        $message="This is a multi-part message in MIME format.

--_1_$boundary
Content-Type: multipart/alternative; boundary=\"_2_$boundary\"

--_2_$boundary
Content-Type: text/plain; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit

$message

--_2_$boundary--
--_1_$boundary
Content-Type: application/octet-stream; name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment

$attachment
--_1_$boundary--";

    if($name!="" && $subject!="" && $message!="") {
    if($email!="") {
        if(preg_match("/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})+$/",$email))
                {
                $output = '<h1 style=\"color:green\">'."Thank you ".$name.'</h1>';
                mail($to, $subject, $message, $headers);
                }
            else {
            echo "<h1 align=\"center\" style=\"color:red\">Please enter a valid email !!</h1>";
            }
        }
    else {
         echo "<h1 align=\"center\" style=\"color:red\">Email should not empty !!</h1>";
         }
    }
    else {
     echo "<h1 align=\"center\" style=\"color:red\">Mail not send successfully !</h1>";
     }
    }
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Mail File</title>
    </head>
<body>
    <?php echo $output; ?>

<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
    <p> Name : <input type="text" name="name" /> * </p>
    <p> Email : <input type="text" name="email" /> * </p>
    <p> Subject <input type="text" name="subject" /> * </p>
    <p> Message <textarea name="message" id="message" cols="20" rows="5"></textarea> </p>
    <p><label for="file">Attach a File : </label> <input type="file" name="file" id="file"></p>

    <p><input type="submit" name="submit" id="submit" value="Send"></p>
</form>

</body>
</html>

Delete Data



<?php include("configuration.php"); ?>
<?php
$result=mysql_query("select*from info") or die (mysql_error());
echo"<table border='1'>
<tr>
                                    <th>Name:</th>
                                    <th>Address</th>
                                    <th>Phone:</th>
                                    <th> Delete </th>
                        </tr>";
while ($row=mysql_fetch_array ($result)) {
            echo"<tr>";
                        echo "<td>" .$row['name']. "</td>";
                        echo "<td>" .$row['address']. "</td>";
                        echo "<td>" .$row[‘cell’]. "</td>";
                        // delete script
                        echo"<td><a href=\"script.php?delid=".$row['id']."\">" .Delete. "</a></td>";
                        echo "</tr>"; }
echo "</table>";
?>
File Name: Script.php
<?php
include("config.php");

// delete data from database start
$del=$_GET['delid'];
$redirect="delete_data.php";
mysql_query("delete from info where id='$del'");
header("Location: $redirect");
// delete data from database start
?>

Loading
Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Flying Twitter Bird Widget By ICT Sparkle