There are many ways to make the serial number automatically, including my version. Let us begin by making a detailed. Here are some source code that you can copy, but you should re-type for easy to remember and quick to understand.
The first step :
Create a database first "otomatis" or bias using a different name. After that create table "nomor". Here's an example of making
create database otomatis;

















Then the table will be stored in the database "otomatis"


Step two :
Create a folder in htdocs "otomatis", so that we can open in Mozilla or Google Chrome and so on. http://localhost/otomatis

Step three :
Create a connection from the database to php, the following source code of koneksi.php












The explanation :

$db_host = "localhost";
$db_user = "root";
$db_pass = "";
$db_data = "otomatis";

To call the host, user, password and database, set according to the databases and passwords from your computer.


$koneksi = mysql_connect ($db_host, $db_user, $db_pass)

To call $koneksi to be a connection to the host, user and password.


Parameter or die (“Connection Failed”.mysql_error());

This is the error message if no database is connected.


Parameter mysql_select_db ($db_data, $koneksi)

will connect to the database host connection, user and password


Fourth step :
The most important are the following source code is useful for automated dialing that we discussed. The following code themselves
<?php
function kdauto($tabel, $inisial){
      $struktur   = mysql_query("SELECT * FROM $tabel");
      $field      = mysql_field_name($struktur,0);
      $panjang    = mysql_field_len($struktur,0);

      $qry  = mysql_query("SELECT max(".$field.") FROM ".$tabel);
      $row  = mysql_fetch_array($qry);
      if ($row[0]=="") {
            $angka=0;
      }
      else {
            $angka = substr($row[0], strlen($inisial));
      }
     
      $angka++;
      $angka =strval($angka);
      $tmp ="";
      for($i=1; $i<=($panjang-strlen($inisial)-strlen($angka)); $i++) {
            $tmp=$tmp."0";   
      }
      return $inisial.$tmp.$angka;
}
?>

Save as kode_auto.php

Fifth step :
Next we make the files index.php, the following source code index.php

<html>
<head>
<title> Untitled Document </title>
</head>

<body>
<form action="simpan.php" method="post" name="form1" target="_self" id="form1">
  <table width="600" align="center" bgcolor="#CCCCCC">
    <tr>
      <td width="209" height="40">Nomor / Kode Pokok / Masalah</td>
      <td width="45"><b>:</b></td>
      <td width="330">
        <input name= "id_nomor" type= "text" id="id_nomor" size= "7" value=" <? echo kdauto("nomor", "NO-"); ?>" disabled= "disabled" />
    <input name= "id_nomor" type= "hidden" id= "id_nomor" size= "7" value= "<? echo kdauto("nomor","NO-"); ?>" />
        / PW01 /
        <select name= "masalah" id= "masalah">
          <option value="1"> 1 </option>
          <option value="2"> 2 </option>
              <option value="3"> 3 </option>
              <option value="4"> 4 </option>
              <option value="5"> 5 </option>
        </select>
        /
        <select name= "tahunnomor">
          <option value= "2013"> 2013 </option>
          <option value= "2014"> 2014 </option>
              <option value= "2015"> 2015 </option>
      </select></td></tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td><input type= "submit" name= "simpan" value= "Simpan" id= "simpan" /></td>
    </tr>
</table>
</form>
</body>
</html>
Add this code below for call connection and <body> kode_auto number to be automatically run.
<?php
include "inc.koneksi.php";
include  "kode_auto.php";
?>

Step six :
In index.php there simpan.php form, then we will make simpan.php files for data storage. By the time we hit the save button, then the index will process the data to form simpan.php and will take place on the database storage. Here's the source code of simpan.php

<?PHP
include "inc.koneksi.php";

            $id_nomor   = $_REQUEST['id_nomor'];
            $masalah    = $_REQUEST['masalah'];
            $tahunnomor = $_REQUEST['tahunnomor'];

      $sql = "INSERT INTO nomor SET
        id_number= '$id_nomor',
        code= '$masalah',
        year= '$tahunnomor'";

      mysql_query($sql, $koneksi)
        or die ("SQL Error".mysql_error());
     
      $pesan = "Data Berhasil disimpan";
      header ("location: index.php?pesan=$pesan");
?>
Explanation :

$id_nomor   = $_REQUEST ['id_nomor'];
$masalah    = $_REQUEST ['masalah'];
$tahunnomor = $_REQUEST ['tahunnomor'];


Will call the data in the form index.php, so needless syntactic $_REQUEST[] so that the data can be in the form simpan.php though.

So, the results of which we have designed can be seen as follows:





When we hit the save button, the number will automatically go up one level (n + 1).

This is all I can explain to you all, if there is an error in typing or program error then comment every post. thank you







1 komentar:

Anonymous said...

mantap... :)

Post a Comment

if you have any questions about posting, feel free to comment.
thank you