我有以下代码,该代码成功为每个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循环中的每个元素仅回显一次
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句