我有这个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脚本中,以便它影响两个表。
任何帮助?
由于
答案 0 :(得分:0)
你可以检查一下:创建一个.css文件并添加一个带有一些有意义名称的类,如.resultTable。 在PHP代码中添加表的类,如下所示
echo "<table class="\"resultTable"\" align='left' cellspacing=3 cellpadding=4 border=1 bgcolor=dddddd>";
答案 1 :(得分:0)
这一行
<table align='left' cellspacing=3 cellpadding=4 border=1 bgcolor=dddddd>
实际上将第一张桌子浮动到左边
请参阅table
中align
的定义。
解决方案:从开始代码中删除align='left'
。
<table cellspacing=3 cellpadding=4 border=1 bgcolor="#dddddd">