php - Check <th> value and update in <td> based on condition -


i have result , json , $response['json'] contain table header columns , table data comes $response['results']. need check if header contain column name "nn id" respective table column data should in anchor <a href="">data</a> tag.

php code:

$json = $response['json']; $result = $response['result'];  echo '<strong>search results</strong>     <h4 class="bg-default"><strong>total records ('.count($result).')</strong></h4>';  if (count($result) > 0) {      echo '<table class="table table-striped table-hover table-bordered">         <thead class="bg-primary">             <tr>';                 foreach (array_values($json) $column) {                     echo '<th>'.$column.'</th>';                 }             echo '</tr>         </thead>         <tbody>';             foreach ($result $row) {                 echo '<tr>';                 foreach (array_keys($json) $field) {                     echo '<td>'.$row[$field].'</td>';                 }                 echo '</tr>';             }         echo '</tbody>     </table>';  } 

need add href for

  <td>      <a onclick="parent.loadiframe(\'/view.php?nnid='.$row[field].'\')">         '.$row[field].'     </a>   </td> 

current view:

enter image description here

need view link nn id column data

enter image description here

a simple if statement need:

foreach ($result $row) {             echo '<tr>';             foreach ( array_keys($json) $field) {                 if ( $field == 'nn id' ) {                     echo '<td><a onclick="parent.loadiframe(\'/view.php?nnid='.$row[$field].'\')">     '.$row[$field].' </a></td>';                 } else {                     echo '<td>'.$row[$field].'</td>';                 }             }             echo '</tr>';         } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -