簡體   English   中英

為group_concat創建單獨的超鏈接,並將結果顯示在一個表格單元格中

[英]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循環中的每個元素回顯一次

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM