Monday, 13 January 2014

MYSQL PHP DATABASE CONNECTION

Hi guyz,

The most useful code snippet in present day web application development is MYSQL PLUS PHP CONNECTION.

for this we require the basic three modules:

Mysql - database
PHP  - Backend scripting language
XAMPP - Server

for developing any web application we require to deal with database hence for maintaining database and for manipulating database we require a server and a specific db language.

here im specifying some MYSQL Commands used for DB CONNECTION

Connecting php with server

      mysql_connect();

Connecting php with database

   mysql_select_db();

For writing any php mysql query we use

  mysql_query();

ex:   mysql_query("SELECT * FROM table_name WHERE col='$data' ");

For fetching data from this query

ex: mysql_fetch_array($query);

For counting number of rows

ex:  mysql_num_rows($query);

Php mysql tester:

An example programm - for database connection:

Programm name : db_connection.php

<?php
$hostname = ''localhost';
$username = 'root';   //for local server
$password  = '';     // empty for local server
$database = 'example_db';
mysql_connect($hostname,$username,$password);
mysql_select_db($database);
mysql_close();
?>

Example programm - 2

Program name : check_sql.php
<html>
 <head> <title>   checking the database </title> </head>
<body>
<?php

include('db_connection.php');  // including the db connection

?>
<center>
<h2> printing all the values from the datase table </h2>

<br><br>

<?php

$k = mysql_query("SELECT * FROM users ORDER BY u_id DESC");
if($mysql_num_rows($k)>0) {        //    number of rows

while($kk = mysql_fetch_array($k))    // fetching array
{
echo $name = $kk['name'];        //  printing the names from name coloumn in table
echo  $id_no = $kk['id_num'];      //  printing id numbers from id_number  coloumn in table
}

}

?>

</br>

<h2> All the values are printed </h2>

















read more...

FLAMES IN JAVA

Here is the flames code in java.

The number for counting  will be depends on the two names given at the begining.

import java.util.*;
import java.lang.*;
class flame{
public static void main(String args[]){
int i,n,m,l,l1,k,j,count=0;
char o;
String n1,n2,f,g,krish,fd;
String[] sA;
String[] e;f="FLAMES";
System.out.println("*************************************"); System.out.println();System.out.println("\t KRISHCDBRY PRESENTS");
 System.out.println("\t ----  FLAMES  ----");
 System.out.println();
System.out.println("*************************************");
 System.out.println();
StringBuilder mF = new StringBuilder(f);
try {
System.out.println("HAI, ENTER BOTH OF YOUR FULL NAMES...");
System.out.println();
Scanner sc = new Scanner(System.in);
Scanner sc1 = new Scanner(System.in);
n1 = (sc.nextLine()).toUpperCase();
 n2 = (sc1.nextLine()).toUpperCase();
 l = n1.length();
 l1 = n2.length();
for(i=0;i<l;i++){
for(j=0;j<l1;j++) {
 if(n1.charAt(i)==n2.charAt(j)){
count = count+1;
}
}
}
n = (count*10)+(l+l1);
for(i=6;i>1;i--)
{
 l = mF.length();
k = (n-1)%l;
  mF.setCharAt(k, '.');
 g = new String(mF);
if(g.charAt(l-1) != '.'){
sA = g.split("\\.");
mF = new StringBuilder(sA[1].concat(sA[0]));
}
else{   krish = ""+g.charAt(0);
  for(j=1;j<l-1;j++)  {  
 krish = krish+""+g.charAt(j);
   mF = new StringBuilder(krish);
  }}}
fd = ""+mF; System.out.println();

if(fd.equals("F")||fd.equals("F.")){  System.out.println("YOU BOTH ARE GOOD FRIENDS");                 }
if(fd.equals("L")||fd.equals("L.")) {  System.out.println("YOU BOTH ARE DEEP LOVERS");                 }
if(fd.equals("A")||fd.equals("A.")) {   System.out.println("YOU BOTH HAVE AFFECTION TO EACH OTHER");                }
if(fd.equals("M")||fd.equals("M.")) {  System.out.println("YOU WILL GET MARRIED");                 }
if(fd.equals("E")||fd.equals("E.")) {  System.out.println("YOU BOTH ARE ENEMIES");                 }
if(fd.equals("S")||fd.equals("S.")) {   System.out.println("YOU BOTH ARE SIBLINGS");                }
}

catch(Exception x){ }}}


read more...

SIMPLE CALC VIA JAVASCRIPT

Hey guyzz , now im going to give a code for creating simple calculator in javascript.

Just create a html page with one table , in that one text box for typing number which were going to be calculated and also to display result.

Then buttons which are labeled with numbers and symbols.

here is the ,
JAVASCRIPT CODE

<script type="text/javascript">

var i = ""; var j = ""; var k = ""; var p="";
   function add_num(n){
   
     if(n==100){   j=j+0; p="1";
       document.getElementById("calc").value = "+";
        }else if(n==101){
        if(p==1){document.getElementById("calc").value = i = Number(i)+Number(j);  }
        if(p==2){document.getElementById("calc").value = i= Number(i)*Number(j); }
        if(p==3){ document.getElementById("calc").value = i=  i/j; }
        if(p==4){document.getElementById("calc").value = i =Number(i)-Number(j);}
          p=""; j="";
        }else if(n==102){
    j=j+0;  p="2";
       document.getElementById("calc").value = "*";
    }else if(n==103){
    j=j+0;  p="3";
       document.getElementById("calc").value = "/";
    }else if(n==104){
    j=j+0;  p="4";
       document.getElementById("calc").value = "-";
    }else if(n==105){
    p=""; i=""; j="";
       document.getElementById("calc").value = "";
    }
    else{
    if(j.length==0){
            i=i+n;
        document.getElementById("calc").value = i;
    } else {
    j=j+n;
        document.getElementById("calc").value = j;
        }
    }
     

   }


</script>


The above javascript includes a function add_num which is used to take a integer value like "n" and then depending on the value it further proceeds.

Now creating a html page , mainly creating buttons with onclick function "add_num".

HTML CODE:

<body>
<table><tr><td>
<center><h2>Calculator</h2></center>

    <input type="text" name="calc" id="calc"  placeholder="Calculate here">
<br><br>
<input type="button" value="    1    " onclick="add_num('1')">
<input type="button" value="    2    " onclick="add_num('2')">
<input type="button" value="    3    " onclick="add_num('3')"> <br>
<input type="button" value="    4    " onclick="add_num('4')">
<input type="button" value="    5    " onclick="add_num('5')">
<input type="button" value="    6    " onclick="add_num('6')"><br>
<input type="button" value="    7    " onclick="add_num('7')">
<input type="button" value="    8    " onclick="add_num('8')">
<input type="button" value="    9    " onclick="add_num('9')"><br>
<input type="button" value="    0    " onclick="add_num('0')">
<input type="button" value="    +    " onclick="add_num('100')">
<input type="button" value="    *    " onclick="add_num('102')"><br>
<input type="button" value="    /    " onclick="add_num('103')">
  <input type="button" value="     -    " onclick="add_num('104')">
<input type="button" value="    c    " onclick="add_num('105')"><br>
<input type="button" value="    =    " onclick="add_num('101')" class="result">
</td></tr></table>
</center>

</body>

here is the html code which includes a text box with id and name and nearly 16 buttons with 0-9 numbers and some calculation symbols like +,-,/,* and one result symbol "=".

On clicking each button will call add_num function.

You can add CSS for cool look..!








read more...

SIMPLE ARRAY EXTENSION

Hi guyz,
Acutally , in native javascript array we can make the array extension by using prototype.....................!
i mean we can extend the array  using this prototype keyword by just writing the array followed by . and then prototype then the function name we want to use in the extension

here we goes with the example

<script>
Array.prototype.remove = function(mem){
var n = this.indexOf(mem);
if(n>-1){
this.splice(n,1);
} return this;
}
['a','b','c','d','e'].remove("c"); // removes c successfully
// or we can write like this
var ar = new Array(('a','b','c','d','e');
document.writeln(ar.remove(c));
// it prints the array without c
</script>

Now we are using simply the method like

a.splice(index_num,number_of_values);

"JavaScript: The World's Most Misunderstood Programming Language"
read more...
 
Copyright © 2014 krishcdbry • All Rights Reserved.
Distributed By Free Blogger Templates | Template Design by BTDesigner • Powered by Blogger
back to top