[英]Add a hyperlink only to one column of a table
I have some query that extracts data from the database like this: 我有一些查询可以从数据库中提取数据,如下所示:
|17DATE00 |concat(filename, fileextension) |
|-----------|--------------------------------|
|2017-05-30 |filename00000.pdf |
|2017-03-29 |filename00002.doc |
Now for the second column, I have passed the link of the doc, so you can click on it and download it. 现在,对于第二列,我已经传递了文档的链接,因此您可以单击它并下载它。
This is the way I extract the data 这是我提取数据的方式
$header = array("17DATE00", "concat(filename, fileextension)");
echo "<thead><tr>";
foreach ($header as $list) {
echo '<th >' . $list . '</th>';
}
echo "</thead></tr>";
foreach ($query as $key => $value) {
foreach ( $value as $a ) {
$url = get_template_directory_uri();
echo '<td><a href="'.$url.'/folder/' . $a . '">'. htmlspecialchars($a) .' </a></td>';
}
echo '</tr>';
}
Doing this, both columns get hyperlinked, while I only need the second one. 这样做,两列都将超链接,而我只需要第二列。 Anyway to fix this?
有任何解决这个问题的方法吗?
Add a counter to you inner loop: 向您的内循环添加一个计数器:
$counter = 0;
foreach ( $value as $a )
{
$url = get_template_directory_uri();
if ($counter == 1)
{
echo '<td><a href="'.$url.'/folder/' . $a . '">'. htmlspecialchars($a) .' </a></td>';
}
else
{
echo '<td>'. htmlspecialchars($a) .'</td>';
}
$counter++;
}
仅当$key == "concat(filename, fileextension)"
才应打印链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.