【问题标题】:Add space between two tables in php在php中的两个表之间添加空格
【发布时间】:2016-12-13 02:39:53
【问题描述】:

我有这个 php 脚本:

<?php
$gene = $_POST["gene"];

$enlace = mysqli_connect("localhost","root","emi22mar6","refGene");
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

mysqli_select_db($enlace,"refGene_human");
$result = mysqli_query($enlace,"select * from refGene_human where name2 like '%$gene%'");

echo "<h1>RefGene Results</h1>";

echo "<table align='left' cellspacing=3 cellpadding=4 border=1 bgcolor=dddddd>";
echo "<tr align='center'><th>Transcript</th><th>Gene</th><th>Chromosome</th><th>Strand</th><th>Gene_Start</th><th>Gene_End</th><th>CDS_Start</th><th>CDS_End</th><th>ExonCount</th>";
while ($extraido = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>".$extraido['name']."<br/>";
echo "<td>".$extraido['name2']."<br/>";
echo "<td align='center'>".$extraido['chrom']."<br/>";
echo "<td align='center'>".$extraido['strand']."<br/>";
echo "<td align='right'>".$extraido['txStart']."<br/>";
echo "<td align='right'>".$extraido['txEnd']."<br/>";
echo "<td align='right'>".$extraido['cdsStart']."<br/>";
echo "<td align='right'>".$extraido['cdsEnd']."<br/>";
echo "<td align='right'>".$extraido['exonCount']."<br/>";
}
echo "</table>";

mysqli_free_result($result);
mysqli_close($enlace);


$enlace2 = mysqli_connect("localhost","root","emi22mar6","refGene");
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }


mysqli_select_db($enlace2,"go_association_human");
$result2 = mysqli_query($enlace2,"select * from go_association_human where db_object_symbol like '%$gene%'");

echo "<h1>GO_Association Results</h1>";

echo "<table align='left' cellspacing=3 cellpadding=4 border=1 bgcolor=dddddd>";
echo "<tr align='center'><th>DB</th><th>Gene_ID</th><th>Gene_Symbol</th><th>GO_id</th><th>GO_reference</th><th>Association</th><th>Type</th><th>Date</th><th>Assigned_by</th>";

while ($extraido2 = mysqli_fetch_array($result2)){
echo "<tr>";
echo "<td>".$extraido2['db']."<br/>";
echo "<td>".$extraido2['db_object_id']."<br/>";
echo "<td>".$extraido2['db_object_symbol']."<br/>";
echo "<td>".$extraido2['go_id']."<br/>";
echo "<td>".$extraido2['db_reference']."<br/>";
echo "<td>".$extraido2['db_object_name']."<br/>";
echo "<td>".$extraido2['db_object_type']."<br/>";
echo "<td>".$extraido2['date']."<br/>";
echo "<td>".$extraido2['assigned_by']."<br/>";
}

echo "</table>";

mysqli_free_result($result2);

mysqli_close($enlace);
?>

这会生成两个表,但我想在它们之间添加空格,以便第二个标题“关联结果”位于两个表之间并将它们分开,就好像这个标题在第二个表上方一样。现在的代码生成两个连续的表格,它们之间没有间距,并将第二个标题放在第一个表格旁边...

我知道解决方案涉及通过 css 或类似的方式为表格添加一些边距,例如添加这种代码:

<style type="text/css">
table{
  margin: 10px 0;
}
</style>

但我不知道如何将该 css 代码集成到 php 脚本中,以便它影响两个表。

有什么帮助吗?

谢谢

【问题讨论】:

  • 您可以在页面的任何位置包含 CSS。你不需要在 PHP 中回显它。
  • @MrLister 不是很好的做法,一些浏览器甚至会抛出一些东西。
  • @MrLister 有趣的是,它将在 HTML 但不是 XHTML 中验证。所以我想我们既是对的又是错的 ;-) TBH,我不得不对此进行更多研究,并在 Stack stackoverflow.com/q/4020374/1415724 和关于“XHTML”stackoverflow.com/a/4020384/1415724
  • @MrLister 我知道,但如果在某个时候确实如此呢?我们不知道他们将来会做什么,除非你把那些花哨的水晶球扔给我;-) 让我们同意不同意。
  • @MrLister 我不得不提交一个答案来概述他们所有的错误,因为“一个评论”框中没有足够的空间。我选择不这样做,害怕被追到一个潜在的深兔子洞;这是你的全部;-)

标签: php html css mysql


【解决方案1】:

你能检查一下吗:创建一个 .css 文件并添加一个具有一些有意义名称的类,例如 .resultTable。 在 php 代码中添加表的类,如下所示

echo "<table class="\"resultTable"\" align='left' cellspacing=3 cellpadding=4 border=1 bgcolor=dddddd>";

【讨论】:

    【解决方案2】:

    这一行

    <table align='left' cellspacing=3 cellpadding=4 border=1 bgcolor=dddddd>
    

    实际上将第一个表浮动到左侧。
    参见tablealign的定义。

    解决方法:去掉开始标签中的align='left'

    <table cellspacing=3 cellpadding=4 border=1 bgcolor="#dddddd">
    

    【讨论】:

      猜你喜欢
      • 2017-08-09
      • 2015-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-20
      • 1970-01-01
      • 2015-08-23
      • 1970-01-01
      相关资源
      最近更新 更多