-2

What I need is I want to automatically highlight the entire row that has 'KIV' value. The 'KIV' value is fetched from the database under 'masalah' field.

Here is my code:

<table  id="myTable" class="w3-table-all w3-small w3-striped w3-hoverable w3-responsive">
<thead>
            <tr>
                                          
                        <th></th>
                        <th></th>
                        <th class="text-center">Daerah</th>
                        <th class="text-center">Checkers</th>
                        <th>Nama Pesara</th>
                        <th class="text-center">No. Kad Pengenalan</th>
                        <th>No. Fail</th>
                        <th>Jawatan</th>
                        <th >Tarikh Bersara</th>
                        <th>Jenis Bersara</th>
                        <th>Umur Bersara</th>      
                        <th >Tarikh Dokumen Diterima</th>
                        <th>Tarikh Kuiri</th>
                        <th >Tarikh Dokumen Lengkap</th>
                        <th >Tarikh Hantar KPM</th>
                        <th >Tarikh Sokongan KPM</th>
                        <th >Tarikh Hantar KWAP</th>
                        <th >Tarikh Lulus KWAP</th>
                        <th>Catatan</th>
            </tr>
</thead>
<tbody>

<?php
include('connection.php');

if (isset($_GET['page_no']) && $_GET['page_no']!="") {
    $page_no = $_GET['page_no'];
    } else {
        $page_no = 1;
        }

    $total_records_per_page = 20;
  $offset = ($page_no-1) * $total_records_per_page;
    $previous_page = $page_no - 1;
    $next_page = $page_no + 1;
    $adjacents = "2"; 

    $result_count = mysqli_query($con,"SELECT COUNT(*) As total_records FROM rekod_pesara");
    $total_records = mysqli_fetch_array($result_count);
    $total_records = $total_records['total_records'];
  $total_no_of_pages = ceil($total_records / $total_records_per_page);
    $second_last = $total_no_of_pages - 1; // total page minus 1

    $result = mysqli_query($con,"SELECT * FROM rekod_pesara LIMIT $offset, $total_records_per_page");
    while($row = mysqli_fetch_array($result)){

        echo "<tr>  
        
             '<td><a  href="datarekod.php?id='.$row['id'].'" class="btn btn-primary" ></a></td>' .
             "<td class='a'>".$row['masalah']."</td>
              <td>".$row['daerah']."</td>
              <td>".$row['checkers']."</td>
              <td>".$row['nama_pesara']."</td>
              <td>".$row['no_kp']."</td>
              <td>".$row['no_fail']."</td>
              <td>".$row['jawatan']."</td>
              <td>".$row['tarikh_bersara']."</td>
              <td>".$row['jenis_bersara']."</td>
              <td>".$row['umur_bersara']."</td>
              <td>".$row['tar_terima_dok']."</td>
              <td>".$row['tar_kuiri']."</td>
              <td>".$row['tar_lengkap_dok']."</td>
              <td>".$row['tar_hantar_KPM']."</td>
              <td>".$row['tar_sokongan_KPM']."</td>
              <td>".$row['tar_hantar_KWAP']."</td>
              <td>".$row['tar_lulus_KWAP']."</td>
              <td>".$row['catatan']."</td>
              
              </tr>";
        }
       mysqli_close($con);
    ?>
      <script type="text/javascript">
        $('td a').click(function(e){
        // prevent browser following link
        e.preventDefault();
        //open in new window
        window.open(this.href,"","width=1000,height=650,top=100,left=100" );
         });
      </script>

</tbody>
</table>

Output as follows enter image description here

But, what I need is the entire row with 'KIV' value only will be highlighted. I hope anyone can help me.. thank you in advance..

naddy
  • 3
  • 3

1 Answers1

0

It's a simple case of using an if statement, or, as in my example below, shortening that to a ternary operator

"<td class='a'".($row['masalah'] == "KIV" ? "style='background-color:red'" : "").">"

N.B. If you want to do it on the whole row you'll need to set the style on the enclosing <tr> rather than a single <td>, but the basic approach is the same. (Your example code doesn't contain any <tr>s but I assume you must have omitted them for brevity.)

ADyson
  • 57,178
  • 14
  • 51
  • 63
  • thank you so much, friend. :') I spent almost a week looking for a solution. Finally, I got the answer. <3 – naddy Apr 27 '21 at 02:11