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:
need view link nn id column data
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
Post a Comment