Menampilkan Database Tabel Guru ke web

 Langkah - langkah :

1.Buka CMD :

Microsoft Windows [Version 10.0.26100.6901]

(c) Microsoft Corporation. All rights reserved.


C:\Users\Bahtra-12>cd c://xampparya/mysql/bin


c:\xampparya\mysql\bin>mysql -u root -p

Enter password:

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 8

Server version: 10.4.32-MariaDB mariadb.org binary distribution


Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


MariaDB [(none)]> use db_smk;

Database changed

MariaDB [db_smk]> create table tb_guru(

    -> nip int(25)not null,

    -> nama_guru varchar(200)not null,

    -> jenis_kelamin varchar(15)not null,

    -> tempat_lahir varchar(50)not null,

    -> tanggal_lahir date,

    -> nama_ibukandung varchar(100)not null,

    -> primary key(nip));

Query OK, 0 rows affected (0.023 sec)


MariaDB [db_smk]> INSERT INTO tb_guru VALUES(1001,'Agri','Laki-laki','Sumedang','1991-08-17','Anah');

Query OK, 1 row affected (0.049 sec)


MariaDB [db_smk]> select * from tb_guru;

+------+-----------+---------------+--------------+---------------+-----------------+

| nip  | nama_guru | jenis_kelamin | tempat_lahir | tanggal_lahir | nama_ibukandung |

+------+-----------+---------------+--------------+---------------+-----------------+

| 1001 | Agri      | Laki-laki     | Sumedang     | 1991-08-17    | Anah            |

+------+-----------+---------------+--------------+---------------+-----------------+

1 row in set (0.001 sec)


2.Buat Kode PHP nya :

<?php
include "conn/config.php";

$perintah = "SELECT * FROM tb_guru";
$query = mysqli_query($koneksi, $perintah);

echo "
<h2>Data Guru</h2>
<table border='1' cellspacing='0' cellpadding='8'>
    <tr style='background-color:#f2f2f2;'>
        <th>NIP</th>
        <th>Nama Guru</th>
        <th>Jenis Kelamin</th>
        <th>Tempat Lahir</th>
        <th>Tanggal Lahir</th>
        <th>Nama Ibu Kandung</th>
    </tr>
";

while ($data = mysqli_fetch_array($query)) {
    echo "
    <tr>
        <td>{$data['nip']}</td>
        <td>{$data['nama_guru']}</td>
        <td>{$data['jenis_kelamin']}</td>
        <td>{$data['tempat_lahir']}</td>
        <td>{$data['tanggal_lahir']}</td>
        <td>{$data['nama_ibukandung']}</td>
    </tr>
    ";
}

echo "</table>";
?>

3.Outputnya :



Komentar

Postingan populer dari blog ini

Perintah Insert DML(data Manipulation Langangue)

Fungsi Rekursif

CRUD DataBase menggunakan PHP