Php 检查<;th>;在<;td>;基于条件
我有一个result和一个json,其中$response['json']包含表头列,表数据来自$response['results']。我需要检查标题是否包含作为“NN ID”的列名,然后相应的表列数据应该在锚Php 检查<;th>;在<;td>;基于条件,php,Php,我有一个result和一个json,其中$response['json']包含表头列,表数据来自$response['results']。我需要检查标题是否包含作为“NN ID”的列名,然后相应的表列数据应该在锚标记中 PHP代码: $json = $response['JSON']; $result = $response['RESULT']; echo '<strong>Search Results</strong> <h4 class="bg-def
标记中
PHP代码:
$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) as $column) {
echo '<th>'.$column.'</th>';
}
echo '</tr>
</thead>
<tbody>';
foreach ($result as $row) {
echo '<tr>';
foreach (array_keys($json) as $field) {
echo '<td>'.$row[$field].'</td>';
}
echo '</tr>';
}
echo '</tbody>
</table>';
}
$json=$response['json'];
$result=$response['result'];
echo'搜索结果
总记录('.count($result)。');
如果(计数($result)>0){
回声'
';
foreach(数组_值($json)作为$column){
回显“.$column.”;
}
回声'
';
foreach($结果为$行){
回声';
foreach(数组_键($json)作为$field){
回显'.$row[$field].';
}
回声';
}
回声'
';
}
需要为添加href
<td>
<a onclick="parent.LoadIframe(\'/view.php?nnid='.$row[field].'\')">
'.$row[field].'
</a>
</td>
需要将视图作为NN ID列数据的链接
您只需要一个简单的if语句:
foreach ($result as $row) {
echo '<tr>';
foreach ( array_keys($json) as $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>';
}
foreach($result作为$row){
回声';
foreach(数组_键($json)作为$field){
如果($field=='NN ID'){
回声'
“.$行[$字段]。”
';
}否则{
回显'.$row[$field].';
}
}
回声';
}
这一点仍然不清楚:定义“标题包含列名为“NN ID”。给我们一个数据示例和示例输出。Franker,我已经添加了我需要的屏幕截图。我没有看到任何屏幕截图。请再次检查