Hello,
I am trying to create a table which has a sort feature. I mean whenever someone click the table header, the table content must be sorted based on the header. how to do so?
Here is my table codes:
index.php
<!-- Insert New -->
<br><br><br><br>
<div id="inputberita">
<p> </p>
<p> </p><center>
<?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/>
<!--<button type="button" class="button" onClick="parent.location='input_berita_static.php'">Berita Static Baru</button><br><br> -->
<?php
//LOAD NEWS
$result = mysql_query("SELECT * FROM static_page WHERE post_parent='0' ORDER BY post_id ASC") or die(mysql_error());
?>
<table id="admintable" border="1" cellpadding="2" cellspacing="0">
<tr>
<th>Page</th><th>Post</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='post.php?post_id=".$data['post_ID']."'><img src='../images/post.jpg'></a></td>";
//echo '</tr>';
echo "<tr bgcolor='$result2'>";
echo '<td><a href="input_berita_static.php?post_id='.$data['post_id'].'">'.$data['page'].'</a></td>';
echo '<td>';
if($data['post_type']=="post"){
echo '<a href="post.php?post_id='.$data['post_id'].'"><img src="../images/post.png"></a></td>';
}
echo '</tr>';
$i++;
}
?>
</table>
</form>
</div>
</div>
</center>
</div>
<!-- End Insert -->