Hello all, I am trying to learn how to use the OOP in php. Hence I have this structural simple CRUD admin table. I am trying to reorganize them with OOP.
structural_admin.php
<?php
include('../includes/koneksi.php');
//Hapus berita // undefined index: mode
if (!empty($_REQUEST['id']) && !empty($_REQUEST['mode']) && $_REQUEST['mode'] == "delete")
{
$id = $_REQUEST['id'];
$result = mysql_query("DELETE FROM static_page WHERE id =".$id) or die(mysql_error());
$confirmation = !$result ? "Gagal menghapus data." : "Data telah terhapus.";
}
?>
<div align="center">
<div style="width:700px;text-align:left;padding-top:5px;">
<?php if (isset($confirmation)) { echo $confirmation; } ?>
<form method="get" action="<?php $_SERVER['PHP_SELF'] ?>">
<br/>
<a class="topLink" href="input_berita_static.php">Berita Static Baru >></a><br><br>
<?php
//LOAD NEWS
$result = mysql_query("SELECT * FROM static_page") or die(mysql_error());
?>
<table id="admintable" border="1" cellpadding="2" cellspacing="0">
<tr>
<th>Page</th><th>Action</th>
</tr>
<?php
$i=0;
while ($data = mysql_fetch_array($result)){
$result2=($i%2)?'#DFA09D':'white';
echo "<tr bgcolor='$result2'>";
echo '<td>'.$data['page'].'</td>';
echo '<td><a href="admin.php?mode=delete&id='.$data['id'].'">Hapus</a> |<a href="input_berita_static.php?id='.$data['id'].'">Edit</a></td>';
echo '</tr>';
$i++;
}
?>
</table>
</form>
</div>
</div>
</center>
</div>
</div>
Here is what did :
OOP_admin.php
class table{
// define properties
function __autoload(){
echo "has not been defined yet";
}
function load_row(){
$sql = mysql_query("SELECT * FROM static_page") or die(mysql_error());
}
function delete_row() {
}
}
I am confuse which part I need to copy and paste, and which part I need to leave to be written outside of the php class. Can anyone help me reorganize them?