Work with simple code PHP & MySQL

Posted: 5 February 2011 in Programming
Tags: , , ,

Kalau yang ribet gimana cara menampilkan data dari database, ini ada cara simple untuk load data dari MySQL, here the code :

<html>
<head><title>DATA MAHASISWA</title></head>
<body>
<table border="1">	
    <tr>
       <th>NIM</th><th>Nama</th><th>Jurusan</th>
    </tr>	
    <?php
		$Conn = mysql_pconnect("localhost" ,"root", "");
  		mysql_select_db("dbAkademik");
		$sql='SELECT * FROM Mahasiswa ';
 		$kueri=mysql_query($sql,$Conn) or die (mysql_error());
		while($row=mysql_fetch_array($kueri)) {
			echo '<tr>';
			echo "	<td>$row[0]</td><td>$row[1]</td><td>$row[2]</td>";
			echo '</tr>';
		}	?>
</table>
</body>
</html>

Nah ini code yang diganti formatnya, yang diganti adalah perulangan perbaris :

<html>
<head><title>DATA MAHASISWA</title></head>
<body>
<form action="#" method="post" name="form1">
<table  width=100%>
	<?php
		$sql='SELECT * FROM Mahasiswa ';
 		$kueri=mysql_query($sql,$Conn) or die (mysql_error());
		while($row=mysql_fetch_array($kueri)) {
			echo '<tr>';
			echo "	<td width=10%>NIM</td><td width=90%><input type='text' value=$row[0]></td>";
			echo '</tr>';
			echo '<tr>';
			echo "	<td>Nama</td><td><input type='text' width=100 value=$row[1]></td>";
			echo '</tr>';
			echo '<tr>';
			echo "	<td>Jurusan</td><td><input type='text' value=$row[2]></td>";
			echo '</tr>';
		}
	?>
	<tr> <td></td><td><input type="submit" value="Kirim"></td></tr>	</table></form>
</body>
</html>

Semoga bermanfaat.

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s