Wednesday, February 27, 2019

Web 2-3

Latihan 1
Buatlah file 3krs.php
Copy-paste script berikut ini:

<?php
$conn = mysql_connect("localhost","root","");
mysql_select_db("stmikj2",$conn);
$sql = "select * from 1mhs p inner join 1krs b on p.nim=b.nim
inner join 1mk a on a.kdmk=b.kdmk";
$result = mysql_query($sql);
?>

<table cellpadding="5" cellspacing="0" border="1">
<tr>
<th>NIM</th>
<th>Mahasiswa</th>
<th>KDMK</th>
<th>Mata Kuliah</th>
</tr>
<?php while($buku = mysql_fetch_array($result)){?>
<tr>
<td><?php echo $buku['nim'];?></td>
<td><?php echo $buku['nama'];?></td>
<td><?php echo $buku['kdmk'];?></td>
<td><?php echo $buku['mk'];?></td>
</tr>
<?php }?>
</table>

*
Buatlah 3 tabel di mysql untuk file di atas!
Jalankan di browser!

****
Latihan 2
Buatlah file 4krs.php
Copy-paste script berikut ini:

<?php
$conn = mysql_connect("localhost","root","");
mysql_select_db("stmikj2",$conn);
$sql = "select * from 1mhs p inner join 1krs b on p.nim=b.nim
inner join 1mk a on a.kdmk=b.kdmk where b.nim='N3'"  ;
$result = mysql_query($sql);
?>
<table cellpadding="5" cellspacing="0" border="1">
<tr>
<th>NIM</th>
<th>Mahasiswa</th>
<th>KDMK</th>
<th>Mata Kuliah</th>
</tr>
<?php while($buku = mysql_fetch_array($result))
{?>
<tr>
<td><?php echo $buku['nim'];?></td>
<td><?php echo $buku['nama'];?></td>
<td><?php echo $buku['kdmk'];?></td>
<td><?php echo $buku['mk'];?></td>
</tr>
<?php }?>
</table>

*
Jalankan di browser!

***

Latihan 3

Buatlah file 4krscari.php
Copy-paste script berikut ini:
<html>
<body>
<?php
//koneksi ke database mysql, silahkan di rubah dengan koneksi agan sendiri
$koneksi = mysqli_connect("localhost","root","","stmikj2");

//cek jika koneksi ke mysql gagal, maka akan tampil pesan berikut
if (mysqli_connect_errno()){
echo "Gagal melakukan koneksi ke MySQL: " . mysqli_connect_error();
}
?>

<form action="" method="get">
<label>Cari :</label>
<input type="text" name="cari">
<input type="submit" value="Cari">
</form>

<?php
if(isset($_GET['cari'])){
$cari = $_GET['cari'];
echo "<b>NIM: ".$cari."</b>";
}
?>

<table border="1">
<tr>
<th>KDMK</th>
<th>MK</th>
</tr>

<?php
if(isset($_GET['cari'])){
$cari = $_GET['cari'];

$data = mysqli_query($koneksi,"select * from mhs p inner join krs b on b.nim=p.nim
inner join mk a on b.kdmk=a.kdmk where p.nim like  '%{$cari}%'");

}
else{
$data = mysqli_query($koneksi,"select * from mk a inner join krs b on b.kdmk=a.kdmk");
//$data = mysqli_query($koneksi,"select * from krs");
}
//$no = 1;
while($d = mysqli_fetch_array($data)){
?>
<tr>
<td><?php echo $d['kdmk'];?></td>
<td><?php echo $d['mk'];?></td>
</tr>
<?php } ?>
</table>

</body>
</html>

*
Jalankan di browser!


Bitcoin Offers:
Free Bitcoin, Double Bitcoin, Bitcoin Investment, Bitcoin Trading



"Bitcoin and Forex are high risk business. We must join them smartly."

No comments:

Post a Comment