Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>List Nilai per Matakuliah</title>
- <style type="text/css">
- table.hovertable {
- font-family: verdana,arial,sans-serif;
- font-size:12px;
- color:#333333;
- border-width: 1px;
- border-color: #999999;
- border-collapse: collapse;
- }
- table.hovertable th {
- background-color:#c3dde0;
- border-width: 1px;
- padding: 8px;
- border-style: solid;
- border-color: #a9c6c9;
- }
- table.hovertable tr {
- background-color:#d4e3e5;
- }
- table.hovertable td {
- border-width: 1px;
- padding: 8px;
- border-style: solid;
- border-color: #a9c6c9;
- }
- input {
- alignment-adjust: central;
- }
- </style>
- </head>
- <body>
- <?php
- $koneksi = mysql_connect('localhost', 'root', '') or die (mysql_error());
- mysql_select_db('kuliah', $koneksi) or die (mysql_error());
- ?>
- <table class="hovertable">
- <th>No.</th>
- <th>Nim</th>
- <th>Nama</th>
- <th>Kode MK</th>
- <th>Nama MK</th>
- <th>Nilai</th>
- <form action="view.php" method="POST">
- <?php
- $query_all = "SELECT * FROM angka";
- $result_all = mysql_query($query_all) or die (mysql_error());
- $count = mysql_num_rows($result_all);
- $nomor = 1;
- while ($rows = mysql_fetch_object($result_all)){
- ?>
- <tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
- <td><?php echo $nomor++; ?></td>
- <td><input type="text" id="nim" name="nim[]" value="<?php echo $rows->nim; ?>"></td>
- <td><input type="text" id="nama" name="nama[]" value="<?php echo $rows->nama; ?>"></td>
- <td><input type="text" id="kodemk" name="kodemk[]" value="<?php echo $rows->kodemk; ?>"></td>
- <td><input type="text" id="namamk" name="namamk[]" value="<?php echo $rows->namamk; ?>"></td>
- <td><input type="text" size="2" name="nilai[]" id="nilai" value="<?php echo $rows->nilai; ?>"</td>
- </tr>
- <?php
- }
- ?>
- <tr>
- <td>
- <input type="submit" name="submit" value="Simpan">
- </form>
- </td>
- </tr>
- </table>
- <?php
- // Multipe insert case
- if(isset($_POST['submit'])) {
- $nim = $_POST['nim'];
- $nama = $_POST['nama'];
- $kodemk = $_POST['kodemk'];
- $namamk = $_POST['namamk'];
- $nilai = $_POST['nilai'];
- if($nim > 0) {
- $qry = "INSERT INTO angka(nim, nama, kodemk, namamk, nilai, Dates) VALUES "; // Split the mysql_query
- for($i=0; $i<count($nim); $i++) {
- $qry .= "('".$nim[$i]."','".$nama[$i]."','".$kodemk[$i]."','".$namamk[$i]."', '".$nilai[$i]."', NOW()), ";
- }
- $qry = substr($qry, 0, strlen($qry)-2);
- $insert = mysql_query($qry); // Execute the mysql_query
- }
- // Redirect for each cases
- if($insert) {
- $msg = '<script type="text/javascript">window.location.href = "?view&result=added";</script>';
- }
- else {
- $msg = '<script type="text/javascript">alert("Server Error, Kindly Try Again");</script>';
- }
- echo "Data telah diupdate <a href=view.php>Refresh</a>";
- mysql_close($koneksi);
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment