【发布时间】: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 我不得不提交一个答案来概述他们所有的错误,因为“一个评论”框中没有足够的空间。我选择不这样做,害怕被追到一个潜在的深兔子洞;这是你的全部;-)