【问题标题】:create separate hyperlinks for group_concat and display the results into one table cell为 group_concat 创建单独的超链接并将结果显示到一个表格单元格中
【发布时间】:2016-08-08 17:46:49
【问题描述】:

我有以下代码,它成功地为每个 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";      

}
?>

【问题讨论】:

    标签: php hyperlink group-concat


    【解决方案1】:

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

    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 循环中的每个元素只回显一次

    【讨论】:

    • 我很高兴能帮上忙 ;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-07
    相关资源
    最近更新 更多