我有以下代码,它为每个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";
}
?>
答案 0 :(得分:0)
我想问题是你在这里为每个链接创建单独的单元格
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循环中的每个元素回显一次