kencur,sikencur,aplikasi,tips dan trik, informasi,aplikasi sekolah gratis,pendidikan,aplikasi sekolah,bejalar office

Showing the mysql query results without pressing the button

Example : We write the ID of data and will automatic showing the Name who have the ID without pressing button.
Steps to make is:
1. Create your index.html file and the code is:

<html><head><script type="text/javascript" src="sadam.js"></script></head><body>
<form id="form1" name="form1" method="post" action="">
  <input type="text" name="nimnya" id="nimnya" onkeyup="carinama()" onkeydown="carinama()" />
    <label>NAME : &nbsp;
    <span id="namanya">Input Nim to get name</span>

2. Create a javascript file with sadam.js name (in this case I use sadam.js: D) and fill it with this code:

var xmlhttp;
function carinama()
    var thenim = document.getElementById("nimnya").value;
    if(thenim!=" ")
        if (xmlhttp==null)
          alert ("Browser does not support HTTP Request");
        document.getElementById("namanya").innerHTML="Mencari dan mencari....!!";  
        var url="pencari.php";

function hasilcarinama()

    if (xmlhttp.readyState==4)

function GetXmlHttpObject()
    if (window.XMLHttpRequest)
      // code for IE7+, Firefox, Chrome, Opera, Safari
      return new XMLHttpRequest();
    if (window.ActiveXObject)
      // code for IE6, IE5
      return new ActiveXObject("Microsoft.XMLHTTP");
    return null;

3. Create pencari.php file. Php script to call a name to mysql. Fill it with this code:

$server = "localhost";
$username = "root";
$password = "";
$database = "ghagha";

// Conection and choose database on server
$konyek = mysql_connect($server,$username,$password) or die("Koneksi gagal");
mysql_select_db($database) or die("can not open Database");
$nimditulis = $_GET['nim'];
if($nimditulis==''){echo"Input ID to show NAME automatic";}
    $q = @mysql_query("SELECT * FROM mhs WHERE nim='$nimditulis'")or   die("Error, You write a caracter that not valid");
    $ada = mysql_num_rows($q);
    $r = mysql_fetch_array($q);
    if ($ada == 1 ){echo "$r[nama]";}
    else{echo"There are no  nim $nimditulis in database";}

4. Create a database named ghagha then execute the following script:

-- phpMyAdmin SQL Dump
-- version
-- Host: localhost
-- Generation Time: Jul 20, 2010 at 09:14 
-- Server version: 5.1.37
-- PHP Version: 5.3.0


-- Database: `ghagha`

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

-- Table structure for table `mhs`

  `nim` varchar(10) NOT NULL,
  `nama` varchar(25) NOT NULL,
  PRIMARY KEY (`nim`)

-- Dumping data for table `mhs`

INSERT INTO `mhs` (`nim`, `nama`) VALUES
('NIM0001', 'saya saja'),
('NIM0002', 'kamu saja'),
('NIM0003', 'kita saja');

5. Put they in the same directory, open up with your browser, you will get what you want :D

Thanks for coming to my blog.

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *