为groupcat创建单独的超链接,并将结果显示在一个表单元格中


create separate hyperlinks for group_concat and display the results into one table cell

我有以下代码,它成功地为每个group_concat对象创建了单独的链接,但它没有将它们放置在一个表单元格中,而是将它们放置到单独的单元格中。有人能帮我吗?这是完整的代码:

<?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";      
}
?>

我想问题是你在这里为每个链接创建了单独的单元格

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循环

中的每个元素只回显一次