Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <style>
- *{
- margin: 0px;
- padding: 0px;
- font-family: sans-serif;
- }
- body{
- background-color: white;
- }
- table, th, td{
- border: 1px solid black;
- }
- table {
- border-collapse: collapse;
- width: 20%;
- margin: 20px 10%;
- }
- th{
- background-color: #0078c7;
- color: white;
- }
- tr:hover{
- transition: background-color 0.5s;
- background-color: #99ff99;
- }
- #container{
- width: 40%;
- height: auto;
- border: 1px solid #b9cccd;
- margin: 10px 0 20px 5%;
- background: white;
- float: left;
- }
- #container2{
- width: 30%;
- height: auto;
- margin: 10px 0 20px 5%;
- background: white;
- float: left;
- }
- #th{
- border-right: 1px solid white;
- }
- th, td {
- padding: 10px;
- border: 1px solid #0078c7;
- }
- .simpan{
- border: 1px solid #00e500;
- background-color: #19ff19;
- color: white;
- border-radius: 2px;
- margin: 20px 0 20px 30%;
- padding: 10px 30px;
- transition: border-radius 0.5s, background-color 0.5s, color 0.5s;
- }
- .simpan:hover{
- background-color: #009900;
- color: white;
- border-radius: 10px;
- }
- input[type=radio]:checked{
- border: 1px solid red;
- }
- </style>
- </head>
- <body>
- <form method="post">
- <div id="container">
- <table>
- <tr>
- <th id="th">No</th>
- <th id="th">NAMA</th>
- <th>NILAI</th>
- </tr>
- <?php
- for($i=1;$i<=10;$i++){
- echo "
- <tr>
- <td id='no{$i}'>{$i}</td>
- <td><input type='text' name='nama[]'></td>
- <td><input type='text' name='nilai[]'></td>
- </tr>";
- }
- ?>
- </table>
- <div style="margin-left:10%;">
- Pengurutan : <input type="radio" name="data" value="Nama">Nama
- <input style="margin-left:12.5%;" type="radio" name="data" value="Nilai">Nilai<br>
- <input style="margin-left:19%;" type="radio" name="sort" value="ascending">Ascending
- <input style="margin-left:7%;" type="radio" name="sort" value="descending">Descending<br>
- <input type="submit" class="simpan" name="simpan" value="Simpan">
- </div>
- </div>
- </form>
- <?php
- if(isset($_POST['simpan'])){
- $nama=$_POST['nama'];
- $nilai=$_POST['nilai'];
- $gabungan= array_combine($nama,$nilai);
- $sort= $_POST['sort'];
- $data= $_POST['data'];
- if($sort=="ascending"){
- if($data=="Nama"){
- ksort($gabungan);
- }
- else if($data=="Nilai"){
- asort($gabungan);
- }
- }
- if($sort=="descending"){
- if($data=="Nama"){
- krsort($gabungan);
- }
- else if($data=="Nilai"){
- arsort($gabungan);
- }
- }
- echo "<div id='container2'>
- <table>
- <tr>
- <th>No</th>
- <th id='th'>NAMA</th>
- <th>NILAI</th>
- </tr>";
- $no=0;
- foreach($gabungan as $Nama => $Nilai){
- if(!empty($Nama)){
- echo"
- <tr>
- <td style='padding: 10px;'>".(++$no)."</td>
- <td style='padding: 10px auto;'>$Nama</td>
- <td style='padding: 10px auto;'>$Nilai</td>
- </tr>";
- }
- }
- echo "</table>
- </div>";
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement