Posts

Showing posts from 2015

MYSQLI_ASSOC and MYSQLI_NUM

// mysqli_fetch_array($query)                          [General and simple Process] while ($row = mysqli_fetch_array($query)) {         ?>         <tr>             <td><?php echo $row['id']; ?></td>             <td><?php echo $row['name']; ?></td>             <td><?php echo $row['roll']; ?></td>             <td><?php echo $row['created_date']; ?></td>         </tr>         <?php     } // MYSQLI_ASSOC                                    [index names will be same as user defined] while ($row = mysqli_fetch_array($query,MYSQLI_ASSOC)) {         ?>         <tr>             <td><?php echo $row['id']; ?></td>             <td><?php echo $row['name']; ?></td>             <td><?php echo $row['roll']; ?></td>             <td><?php echo $row['created_date'

mysqli Connect, Insert and Query data

// Build Connection with database. $con = mysqli_connect("localhost","hkc","123","test_db"); // Database Connection checking with error numbers if(mysqli_connect_error()){         echo "Connection Error Number is : ".mysqli_connect_errno();     } // Specify values for enjoined fields of destination table. Type 01 : $insert = "INSERT INTO test_table(name,roll,created_date) VALUES('Hasib',4153,NOW())"; Type 02 : $insert = "INSERT INTO test_table VALUES(null,'romel',4160,NOW())"; //Built Connection and send data into fields. mysqli_query($con,$insert); // Create Query $query = mysqli_query($con,"SELECT * FROM test_table"); // To get few info by your query print_r($query) // Object oriented using this operator $query->num_rows;                                 [**num_rows found from print_r($query); ] // Fetch data row by row, by using while loop while ($row = mysqli_

SQL connection and check error

Set SQL connection and check error with error numbers. <?php $con = mysqli_connect("localhost","root","","testdb"); if(mysqli_connect_errno()){     echo "Faild to connect My SQL : ".mysqli_connect_error(); } ?>

Basic difference for subtraction with two formula

 Formula 1 :                    387                    -98                   ------                   289 1st step we borrow 1/(10) from 8 and then make 7 into 17. (17-8=9). 2nd step we add borrowed 1 with 9 and again borrow 1/(10) from 2. (18-10=8). 3rd step we subtract  borrowed 1 from 3. (3-1=2). ______________________________________________________________ Formula 2 :                  387                  -98                 ------                 289 1st step we borrow 1/(10) from 8 and then make 7 into 17. (17-8=9). 2nd step we subtract borrowed 1 from 8 then situation is (7-9) so we again borrow 1/(10) from 2. (17-9=8). 3rd step we subtract  borrowed 1 from 3 and than (2-0=2).

Call by reference in php OOP

<?php     class a{         public function calc(&$a,&$b){             return $a+$b;         }     }     $obj = new a();         $v1=2;         $v2=4;     echo $obj->calc($v1,$v2); ?> When you will pass value by reference then remember you must have to use '&' sing in parameter with variable as like as the example given up.

Regular Expression

1. ([a-z]+) this expression will count a word from small a to small z. Such as according to this code which is given below. <?php     $preg = "aAAAA Bbbbb bbbbb bbbbbb";     echo preg_replace("([a-z]+)", "1", $preg); ?> You will get this output '1AAAA B1 1 1'. 2. ([a-z]) this expression will count a single character from small a to small z. Such as according to this code which is given below. <?php     $preg = "aAAAA Bbbbb bbbbb bbbbbb";     echo preg_replace("([a-z])", "1", $preg); ?> You will get this output '1AAAA B1111 11111 111111'.

php preg_replace

preg_replace is a function which is use in regular expression. <?php     $preg = "aAAAA Bbbbb";     echo preg_replace("([a-z])", "1", $preg); ?> There $preg is a variable and we stored some strings in this variable. preg_replace(); function is a builtin function which has three parameters. First parameter is for regular expression condition, the second one is for required output, and the last and third parameter is to select the variable that in which variable you want to apply preg_replace() function.

PHP Public, Private, Protected

In php (object oriented programming) you can define three types of variable in class. Usually variable in class is called by operator. Three types are public,private,and protected. public : When you will define public type. You can access it anywhere. Inside of it's own class or another class or outside of the class. protected : When you will define protected type. You can access it only in class. Not only in it's own class but also it can access in another class but never outside the class protected type is accessible. private : Private is the most secure type. It is only accessible in it's own class. And not accessible neither other class nor outside of any class.

Object Oriented Programming PHP

PHP is also object oriented programming....... <?php     class abc{         function hkc(){             echo "Hasib Kamal Chowdhury";         }     }     $object = new abc;     echo $object->hkc(); ?> This is very basic example of OOP in PHP. Here, At first of all we have to create a class. In this code we created a class named 'abc' and in this class we declared a function named 'hkc()'. So, Now the question is how we will call the function hkc() from the class 'abc'. In the next step we have to create an object. $object is something like as variable where we contained the class 'abc'. Procedure shown below how to make object. $variable = new abc; This is the procedure to create object. Now we will call hkc() function from $object. The procedure of calling function from object is shown below. $object->hkc();

Sum values in foreach loop _php

http://stackoverflow.com/a/16535758/5530859 $sum = 0;     foreach($group as $key=>$value)     {        $sum+= $value;     }     echo $sum;

SelectOption list with link by javascript

        <select onchange="window.location=this.value">             <option value="http://www.google.com">Google</option>             <option  value="http://www.yahoo.com">yahoo</option>             <option  value="http://www.twitter.com">Twitter</option>         </select>

Image size output by php

<?php   echo number_format($_FILES['photo']['size']/1024/1024,4,'.',''); ?> Here is the format to view the file size. At the beginning file size will shown as byte when we will write the code as follows, echo number_format($_FILES['photo']['size']); We know 1024 byte = 1kb. So if we want to represent the size as kilobyte format we have to divide the size by 1024 so the code will be like that, echo number_format($_FILES['photo']['size']/1024); But if we want to show the file size as megabyte format we have to divide this again by 1024 cause we know 1024kb = 1mb. And the coding will be like that, echo number_format($_FILES['photo']['size']/1024/1024); There is a problem if you divide 100/1024 that means if you divide 100kb by 1024kb to convert megabyte you will get out put 0. Cause after point values are not printing. So what is the solution to get the values after point. Here is your code given

Generate options by using user defined function

<?php   function generateOptions($start,$end,$inc){     $options = '';     for($i=$start; $i<=$end; $i+=$inc){        $options = $options."<option>".$i."</option>";     }     return $options;      }  ?> <select name="year">   <option>Year</option>   <?php   echo generateOptions(1900,date('Y')-10,1);   ?> </select>  

php Loop

<?php //For Loop for($i=0; $i<=12; $i++){   echo "For Loop : ".$i."<br>"; } //While Loop $j = 30;   while($j<=40){     echo "While Loop : ";     echo $j++;     echo "<br>";   } //Do While Loop   $k = 20;   do{     echo "Do While Loop : ";     echo $k++;     echo "<br>";   }while($k<=50)   ?>

Calculate total sum of all values from loop

<?php     function calsum($start,$end,$inc){         $sum = 0;         for($i=$start; $i<=$end; $i+=$inc){             echo "<pre>";             echo $i;             $sum = $sum + $i;             echo "<br>";         }         echo $sum;     }         calsum(1,3,1); ?> There is an user defined function called calsum(); In this this function total three parameters has been taken. We will run a loop in this function. User's input will be the start value, end value, and the increment value. Here user want to start loop from 1 and want to end to 3 and the increment gap will be one. So we will run the loop and show the output from 1 to 3 and we will get increment gap 1. But here we also want to get the total sum of the loop. So at first of all on the upper of loop we have declared a initial variable named $sum. And which initial value is 0. And the value will increase with each rotation of loop. After end of the loop we will ec

Generate function for date by loop in form

<?php   function generateOptions($start,$end,$inc){     $options = '';     for($i=$start; $i<=$end; $i+=$inc){       $options = $options.'<option>'.$i.'</option>';     }       return $options;   } ?>        <select>           <option>Day</option>             <?php echo generateOptions(1,31,1); ?>         </select>

To get even and odd numbers from a loop by using function

<?php     function evenOdd($start,$end,$type){         for($i=$start; $i<=$end; $i++){             if($type == "even" && $i%2==0){                 echo "<pre>";                 echo $i;             }elseif($type == "odd" && $i%2!=0){                 echo "<pre>";                 echo $i;             }         }     }     evenOdd(10,20,"even"); ?> Here we have created a function named evenOdd(); this is user defined function which have been created. There are three parameters in this function. So total three values will pass through this function. Loop will start from 10 and will be end to 20 and in string part if you write even you will just get even numbers and if you write odd you will get only odd numbers.

% (Modulus)

$i = 10%7; Output = 3. $j = 10%3; Output = 1. '%' This is an arithmetic operator in php which is named by modulus. This is use for get the modulus values. Suppose you have coded 10%3. So what will happen here ?? We know 10 will be divided by 3 total three times and remain 1 as modulus value. 

array_merge(array1); More than one arrays value get together

array_merge(array1,array2,array3); this function is use for merge multiple array together. Concept will be clear with an example. <?php     $arr1 = array("Ball","Bat","Stamp");     $arr2 = array("CPU","Monitor","Keyboard");     echo "<pre>";     print_r(array_merge($arr1,$arr2)); ?> There is two array $arr1 and $arr2. If we want to get those arrays values together we have to use array_merge(); function like that. And you will get all values together.

array_values(input); To get all values from an array

array_values(); This function is use to get all values from a defined variable. The concept will be more clear if we look at an example. <?php     $val = array("car"=>"BMW","pen"=>"Econo","brand"=>"Dell");         echo "<pre>";         print_r(array_values($val)); ?> Here $val variable is an array where stored some values and keys. So now if we just want to print only values on screen. What is the solution ?? Yes... There is a solution by array_values(); function. If we input the variable in the function we will get the output. Then only values from the array will get out as output.

array_keys(input); To get all keys from an array

array_keys(); This function is use to get all keys from a defined variable. The concept will be more clear if we look at an example. <?php     $var = array("car"=>"BMW","pen"=>"Econo","brand"=>"Dell");         echo "<pre>";         print_r(array_keys($var)); ?> Here $var variable is an array where stored some values and keys. So now if we just want to print only keys on screen. What is the solution ?? Yes... There is a solution by array_keys(); function. If we input the variable in the function we will get the output. Then only keys from the array will get out as output.

array_key_exists(key, search)

array_key_exists(); this function is used to justify key. For the clear concept codes are given below. <?php     $k = array("car"=>"BMW","pen"=>"Econo","brand"=>"Dell");         if(array_key_exists("car", $k)){             echo "This is a key or index";         }else{             echo "This is not any key";         } ?> So the basic concept is this function is used for check your given keyword from your defined array that it's key or not. Here inside the first bracket the first argument will be your given keyword which is key. And the second argument will be arrays name which you have defined as variable.

Case sensitivity in php to defining variable

$hasib = "all words are small letters"; echo $Hasib; You will get an error message cause though variables names are same but you have stored value on $hasib; So what is the different here ?? The major different is $Hasib variable started with capital lertter and $hasib with small letter but those are not same variable although all letters are same in both variable. So careful when you define variable.

Different between two types of array

Array define types      Type A)            $arr[] = "value1";            $arr[] = "value2";      Type B)            $arr = array("value1","value2"); Given up the two types of defining array. When you will define 'A' type array and you will use sort(); function to arrange values by ascending order then only values will be arranged by ascending order not keys. But if you apply sort(); function in 'B' type array you will see that not only array but also keys are being arranged by ascending order by sort(); function. And like that rsort(); function will do the same job. rsort(); function will just arrange by descending order. So if you want to arrange keys or index by ascending order in Type 'A' you have to use the ksort(); function for ascending order and krsort(); function for descending order. But if you use these function on Type 'B' you will see that values and keys are arranging by ascending order or de

array_count_values($var);

print_r(array_count_values($var)); array_count_values(); function is use for count how many common values in an array ?? To clearing the concept suppose you have an array where you have stored your friends names. And you have one name of three friends suppose the name is Aiken. Here array_count_values($friends) will return you [Aiken] => 3 cause this function have found three same values in $friends array. So we able to understand to count the same or common values in an array. 

array_combine();

array_combine(); function is used for make a combination between two arrays. Practical example is similarly  like you have defied two arrays suppose first one is arr1 and 2nd one is arr2. So there is two array arr1 and arr2. So what is gonna be happen next ?? We have to take another variable to understand easily. Suppose we have taken a variable called $comb and in this variable we will code like that array_combine($arr1,$arr2); . So according to array_combine() function first argument is stored as key and second argument as value. Now it's time to print array and we know the code of printing array is print_r();   

array_chunk($var,2);

print_r(array_chunk($var,2)); array_chunk(); function is used for divide the main array into coder requirement. According to practical thinking you can imagine there is a variable and this is array which has total ten values. If you want to print couple of values in per chunk you have to code array_chunk($var,2); function into print_r(); function. Then you will see there will be create five chunk and each chunk is containing two values. But if there would be total 11 values you would get six chunks and in the final chunk will contain the rest of value that means the last chunk will contain only one value. An example coding is given below. <?php     $cnk = array("value1","Value2","Value3","Value4","Value5","Value6","Value7");     echo "<pre>";     print_r(array_chunk($cnk, 2)); ?>

is_array($var);

is_array($var); This function is used to check the variable that it's array or not. If it's an array then this function will return you '1' as output and if it isn't then you will never get any return or out put form this function. So, the basic concept is this function is used to verify variable that it's array or not. 

PHP Array with explanation

<?php  $ar1[] = 10; // index 0 value 10 $ar1[] = 20; // index 1 value 20 echo '<pre>'; // <pre> use to arrangement print of array print_r($ar1); // print_r(); to print array with value and index echo $ar1[0]; // to print the defined array $ar2[1] = 10; // coder define key or index for array $ar2[3] = 20; // her coder define key is 3 print_r($ar2); // to print array $ar3 = array("a","b","c"); // This array define structure is to use contain multiple value in single variable print_r($ar3); // print_r(); to print array $ar4 = array(    // User define numerical & associative key together in an array     0=>"a", // user define numerical key     "z"=>"b", // user define string key     3=>"c" // user define numerical key     ); print_r($ar4);    // print_r(); to print array echo $ar4[3];    // to echo user define index '3' echo '<br/>'; echo '<br/>'; $

? Ternary Operator

[?] this question symbol is ternary operator in php.

PHP include & require

> include 'page.php'; > include_once 'page.php'; > require('page.php'); > require_once('page.php'); These functions are use for include pages from directory. Here include and require() does same job and the other hand include_once and require_once() also does the slimier action. When you have to include same page many time, then how many times you will code [include 'page.php';] you will get result. Such as if you code [include 'page.php';] [include 'page.php';] [include 'page.php';] three times include or only require('page.php'); function then your code will show the [page.php] three times in your coded div though the page is same. But when you will use [include_once ''] or [require_once('')] for same page you will never get your called page more than one time. When you are coding then error happening is simple. The major different between include and require() function is, if php

CDN - Content Delivery Network

http://code.jquery.com/jquery-1.11.2.min.js

twitter bootstrap simple theme

http://startbootstrap.com/assets/img/templates/heroic-features.jpg

Javascript Array

var abc = {                 x: "X",                 y: "Y",                 z: "Z"             };             alert(abc.x);

✖ works really well. The HTML code is ✖

&#10006;

javascript_substring

            var hkc = "bangladesh";             var kc = hkc.substring(6,10);             alert(kc);

javascript variable scope

ফাংশনের ভিতরের ভেরিয়েবল ফাংশনের বাহিরে কল করা যাবে না । কিন্তু ফাংশনের বাহিরের গ্লোবাল ভেরিয়েবল ফাংশনের ভিতরে ব্যাবহার করা যাবে । এই বিষয়টা কে বলা হয় ভেরিয়েবল স্কোপ ।

onclick & onblur

function change_color(ID){             document.getElementById(ID).style.border = "1px red solid";         }         function remove_color(ID){             document.getElementById(ID).style.border = "1px gray solid";         }

window.location

<button onclick="window.location='//www.google.com'">Click to GooGle</button> <select onchange="window.location=this.value">     <option value="http://www.facebook.com/asif24hours">Asif</option>     <option value="http://www.facebook.com/fahim24hours">Fahim</option>     <option value="http://www.facebook.com/nafis24hours">Nafis</option> </select>

document.getElementById('input').innerHTML = "Thowfiqur Rahman Chowdhury";

If we want to print some thing by clicking onto a button by javascript what can we do?? Now have a look.... At first we have to choose a div by 'id' and have to create a function() and a button with 'onclick' option. We will use the function into 'onclick' option. Let see how it be done?? <scirpt>              function trc(){                 document.getElementById('input').innerHTML = "Thowfiqur Rahman Chowdhury";             } </script>  <body>              <div id="input"></div>              <button onclick="trc()">trc</button> </body>

Description of Java Conceptual Diagram

http://docs.oracle.com/javase/8/docs/

Design Javascript Alert Box

https://compriot.com/creating-custom-javascript-alert-box/

Special Characters in HTML

http://www.degraeve.com/reference/specialcharacters.php