Melihat Details Data MySQL menggunakan PHP

//lh4.googleusercontent.com/-eAXyxy2JJKA/AAAAAAAAAAI/AAAAAAAAGS4/OHgzqHzCvtQ/s512-c/photo.jpg
October 03, 2018




Kali ini kami akan share tutorials web sederhana yaitu bagaimana melihat details data MySQL menggunakan PHP. Aplikasi sederhana seperti ini sangat berguna ketika kita mempunyai data yang banyak.


Langsung saja mari kita memulai dari awal , Buat database dengan nama complaint_data kemudian masukkan struktur database dibawah ini.

 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";



CREATE TABLE `tblcomplaints` (
  `complaintNumber` int(11) NOT NULL,
  `RegDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `room` varchar(50) NOT NULL,
  `facilityName` varchar(50) NOT NULL,
  `buildingName` varchar(50) NOT NULL,
  `typedamage` varchar(50) NOT NULL,
  `complaintDetails` mediumtext NOT NULL,
  `status` varchar(25) DEFAULT NULL,
  `lastUpdationDate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
  `pelapor` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tblcomplaints`
--

INSERT INTO `tblcomplaints` (`complaintNumber`, `RegDate`, `room`, `facilityName`, `buildingName`, `typedamage`, `complaintDetails`, `status`, `lastUpdationDate`, `pelapor`) VALUES
(1, '2018-10-02 20:10:20', 'Aquarium Room', 'Proyektor', 'Campus Building', 'Emergency', 'Proyeltornya minta ganti baru', 'Belum Selesai', '2018-10-02 20:01:46', 'Arman'),
(2, '2018-10-02 20:55:43', 'Computer Lab', 'Platform', 'Campus Building', 'Emergency', 'gambarnya tidak begitu jelas', 'Belum Selesai', '2018-10-02 20:55:43', 'Abidzar M'),
(3, '2018-10-02 20:10:20', 'Engineering and Technolog', 'Proyektor', 'Rectorat Building', 'Urgent', 'Pak kira Kira Kapan selesai', 'Selesai', '2018-10-02 20:01:15', 'Kale');

--
-- Indexes for table `tblcomplaints`
--
ALTER TABLE `tblcomplaints`
  ADD PRIMARY KEY (`complaintNumber`);

--
-- AUTO_INCREMENT for table `tblcomplaints`
--
ALTER TABLE `tblcomplaints`
  MODIFY `complaintNumber` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
COMMIT; 

Kedua buat file dengan nama config.php file ini berisi script untuk koneksi kedatabase.

 <?php

define('DB_HOST', 'localhost');
define('DB_USER','root');
define('DB_PASS' ,'');
define('DB_NAME', 'complaint_data');
$con = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);
// Check connection
if (mysqli_connect_errno())
{
 echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

?> 

Ketiga buat file dengan nama index.php file ini berisi script sebagai form data yang ada di database.


 <?php session_start();
error_reporting(0);
include('config.php');
?>

<!DOCTYPE html>
<html>
<head>
  <title>Details Data</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
  <br /><br />
  <div class="container">
   <nav class="navbar navbar-inverse">
    <div class="container-fluid">
     <div class="navbar-header">
      <a class="navbar-brand" href="https://www.tutorialswb.com/">Home</a>
      <a class="navbar-brand" href="index.php">Details Data</a>
    </div>
  </div>
</nav>
<br />
<h2 align="center">View Details Data MySQL Menggunakan PHP</h2>
<br />
<p style="padding-left:20%; color:green">
  <form name="bulk_action_form" action="action.php" method="post" onSubmit="return delete_confirm();"/>
  <table class="table table-bordered">
    <thead>
      <tr>
        <th>No</th>
        <th>Reg Date</th>
        <th>Room</th>
        <th>Nama Fasilitas</th>
        <th>Status</th>
        <th>Action</th>
      </tr>
    </thead>

    <tbody>
      <?php $query=mysqli_query($con, "select * from tblcomplaints"); while($row=mysqli_fetch_array($query)) { ?>                   
        <tr>
          <td><?php echo htmlentities($row['complaintNumber']);?></td>
          <td><?php echo htmlentities($row['RegDate']);?></td>
          <td><?php echo htmlentities($row['room']);?></td>
          <td><?php echo htmlentities($row['facilityName']);?></td>
          <td class="numeric">
            <?php $status=$row[ 'status']; if($status=="" or $status=="NULL" ) { ?>
              <span class="badge badge-secondary">Belum di Proses</span>
            <?php } if($status=="Belum Selesai" ){ ?>
              <span class="badge badge-secondary">Belum Selesai</span>
            <?php } if($status=="Selesai" ) { ?>
              <span class="badge badge-secondary">Selesai</span>
            <?php } ?>
            <td class="numeric">
              <a href="details.php?cid=<?php echo htmlentities($row['complaintNumber']);?>">
                <button type="button" class="btn btn-primary">View Details</button>
              </a>
            </td>
          </td>
        </tr>

      <?php  } ?>
    </tbody>
  </table>
</form>
</div>
</body>
</html>
 

Terakhir buat file dengan nama details.php file ini berisi script details komplaint yang ada di file index.php. Pemanggilan details komplaint menggunakan complaintNumber.

 <?php session_start();
error_reporting(0);
include('config.php');
?>

<!DOCTYPE html>
<html>
<head>
  <title>Details Data</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
  <br /><br />
  <div class="container">
   <nav class="navbar navbar-inverse">
    <div class="container-fluid">
     <div class="navbar-header">
      <a class="navbar-brand" href="https://www.tutorialswb.com/">Home</a>
      <a class="navbar-brand" href="index.php">Details Data</a>
    </div>
  </div>
</nav>
<br />
<h2 align="center">View Details Data MySQL Menggunakan PHP</h2>
<br />
<table class="table table-bordered">
  <tbody>
    <?php $query=mysqli_query($con,"select * from tblcomplaints where tblcomplaints.complaintNumber='".$_GET['cid']."'");
    while($row=mysqli_fetch_array($query))
    {
      ?>                                  
      <tr>
        <td><b>Complaint Number</b></td>
        <td><?php echo htmlentities($row['complaintNumber']);?></td>                                            
        <td><b>Reg Date</b></td>
        <td><?php echo htmlentities($row['RegDate']);?>
      </td>
    </tr>
    <tr>
      <td><b>Room</b></td>
      <td> <?php echo htmlentities($row['room']);?></td>
      <td><b>Facility Name</b></td>
      <td> <?php echo htmlentities($row['facilityName']);?></td>
    </tr>
    <tr>
      <td><b>Building Name </b></td>
      <td><?php echo htmlentities($row['buildingName']);?></td>

      <td><b>Type Complaint</b></td>
      <td><?php echo htmlentities($row['typedamage']);?>
    </td>
  </tr>
  <tr>
    <td><b>Complaint Details</b></td>
    <td><?php echo htmlentities($row['complaintDetails']);?></td>

    <td><b>Status</b></td>
    <td><span class="badge badge-secondary"><?php echo htmlentities($row['status']);?></span>
    </td>
  </tr>
  <tr>
    <td><b>Updation Date</b></td>
    <td><?php echo htmlentities($row['lastUpdationDate']);?></td>
    <td><b>Reporter</b></td>
    <td><?php echo htmlentities($row['pelapor']);?>
  </td>
</tr>

<?php }?>
</tbody>
</table>
</div>
</body>
</html>
 

Kalian bisa melihat langsung demonya dan bisa langsung download filenya dibawah ini supaya kalian bisa melakukan download langsung filenya.

DEMO        DOWNLOAD

Sekian share kali ini semoga apa yang kami share bermanfaat bagi anda, Jangan lupa share dan tinggalkan komentar dibawah dan mulai berdiskusi dengan kami.


Related Post

SUBSCRIBE TO OUR NEWSLETTER

closed