为 group_concat 创建单独的超链接并将结果显示在一个 table 单元格中
create separate hyperlinks for group_concat and display the results into one table cell
我有以下代码,它成功地为每个 group_concat 对象创建了单独的 link,但不是将它们放在一个 table 单元格中,而是将它们分开放置细胞。
谁能帮我?
这是完整的代码:
<?php
if (isset($search))
{
$count=mysqli_num_rows($query) ;
if($count>=1){
$search_output .= "<hr color=red />$count results for <strong>$search</strong><hr color=red />";
while ($row = mysqli_fetch_array($query,MYSQLI_ASSOC)) {
$Title = $row['Title'];
$Year = $row['Year'];
$Authors = $row['Authors'];
$Journal=$row['Journal'];
$Genes=explode(',', $row['Genes']);
$Data_Type=$row['Data_Type'];
echo"<tr>";
echo "<td>".htmlspecialchars($row['Title'])."</td>";
echo "<td>".htmlspecialchars($row['Year'])."</td>";
echo "<td>".htmlspecialchars($row['Authors'])."</td>";
echo "<td>".htmlspecialchars($row['Journal'])."</td>";
foreach($Genes as $aGenes){
echo "<td><a target=\"_blank\" href='http://www.ncbi.nlm.nih.gov/gene/?term=" .$aGenes."'> ".$aGenes." </a> </td>";
}
echo "<td>".htmlspecialchars($row['Data_Type'])."</td>";
echo"</tr>";
}
}else{
$search_output = "<hr />0 results for <strong>$search</strong><hr />";
}
echo "$search_output";
}
?>
我想问题是您在此处 link 为每个 link 创建单独的单元格
foreach($Genes as $aGenes){
echo "<td><a target=\"_blank\" href='http://www.ncbi.nlm.nih.gov/gene/?term=" .$aGenes."'> ".$aGenes." </a> </td>";
}
而不是这样做
echo '<td>';
foreach($Genes as $aGenes){
echo "<a target=\"_blank\" href='http://www.ncbi.nlm.nih.gov/gene/?term=" .$aGenes."'> ".$aGenes." </a> ";
}
echo '</td>';
那就是将 td 标签移出 foreach 循环,以便它们对 while 循环中的每个元素只回显一次
我有以下代码,它成功地为每个 group_concat 对象创建了单独的 link,但不是将它们放在一个 table 单元格中,而是将它们分开放置细胞。 谁能帮我? 这是完整的代码:
<?php
if (isset($search))
{
$count=mysqli_num_rows($query) ;
if($count>=1){
$search_output .= "<hr color=red />$count results for <strong>$search</strong><hr color=red />";
while ($row = mysqli_fetch_array($query,MYSQLI_ASSOC)) {
$Title = $row['Title'];
$Year = $row['Year'];
$Authors = $row['Authors'];
$Journal=$row['Journal'];
$Genes=explode(',', $row['Genes']);
$Data_Type=$row['Data_Type'];
echo"<tr>";
echo "<td>".htmlspecialchars($row['Title'])."</td>";
echo "<td>".htmlspecialchars($row['Year'])."</td>";
echo "<td>".htmlspecialchars($row['Authors'])."</td>";
echo "<td>".htmlspecialchars($row['Journal'])."</td>";
foreach($Genes as $aGenes){
echo "<td><a target=\"_blank\" href='http://www.ncbi.nlm.nih.gov/gene/?term=" .$aGenes."'> ".$aGenes." </a> </td>";
}
echo "<td>".htmlspecialchars($row['Data_Type'])."</td>";
echo"</tr>";
}
}else{
$search_output = "<hr />0 results for <strong>$search</strong><hr />";
}
echo "$search_output";
}
?>
我想问题是您在此处 link 为每个 link 创建单独的单元格
foreach($Genes as $aGenes){
echo "<td><a target=\"_blank\" href='http://www.ncbi.nlm.nih.gov/gene/?term=" .$aGenes."'> ".$aGenes." </a> </td>";
}
而不是这样做
echo '<td>';
foreach($Genes as $aGenes){
echo "<a target=\"_blank\" href='http://www.ncbi.nlm.nih.gov/gene/?term=" .$aGenes."'> ".$aGenes." </a> ";
}
echo '</td>';
那就是将 td 标签移出 foreach 循环,以便它们对 while 循环中的每个元素只回显一次