Saturday, July 4, 2015

Css

CARA MEMBUAT SCROLL DENGAN PHP, MYSQL DAN CSS

1. Buatlah Koneksi terlebih dahulu
<?php

$host = "localhost";    //nama host

$user = "root";    //username phpMyAdmin

$pass = "";    //password phpMyAdmin

$name = "db_belajar";    //nama database

// ambil database

$koneksi = mysql_connect($host, $user,$pass) or die("Koneksi ke database gagal!");

mysql_select_db($name, $koneksi) or die("Tidak ada database yang dipilih!");

?>

2. Buat Database db_belajar dengan nama table tbl_karyawan

3.Copy dan save file di bawah di htdocx
<html>
<head>
<title>Scrol</title>
</head>
<body>
<style>
div.data{
    width: 57%;
    height: 250px;
    overflow: auto;
    margin : auto;
/*    border-top-style: groove;
    border-bottom-style: groove;
    border-right-style: groove;
    border-left-style: groove;
    border-color: lightblue;*/
    border : 2px solid blueviolet;
    align-content: center;
}

th{
    height: 30px;
    font-family: Arial;
    font-size: 12px;
    background :#ccc;
}
</style>
<h1 align="center">Scrol Php Dan Css</h1>
<div class="data">
    <table>
        <tr>
            <th>No</th>
            <th>Nama</th>
            <th>Tempat Lahir</th>
            <th>Tanggal Lahir</th>
            <th>Alamat</th>
            <th>Bagian</th>
            <th>Status</th>      
        </tr>  
            <?php
            include ('koneksi.php');
            $i = 1;
            $sql = mysql_query("SELECT * FROM tbl_karyawan");
            while($data = mysql_fetch_array($sql)) {
                if($i % 2 == 1) {
                    $color = "#0099ff";
                    }
                else {
                    $color = "white";
                    }
                    echo "<tr bgcolor=$color valign=top>
                                <td>$i</td>
                                <td>$data[nama]</td>
                                <td>$data[tempat_lhr]</td>
                                <td>$data[tgl_lhr]</td>
                                <td>$data[alamat]</td>
                                <td>$data[bagian]</td>
                                <td>$data[status]</td>              
                        </tr>";
                        $i++;
                    }          
            ?>      
              
      
    </table>
  
</div>
</body>
</html>

No comments:

Post a Comment