我完全厌倦了这个编码部分只是为了添加select all选项,我已经成功添加了select all,但问题是如何从mysql数据库中获取数据,为选择所有选项。
我在ma数据库中有8个表,对于搜索框,我必须选择查询搜索词的表,它将从所选表中显示查询词的信息。
这是上面的代码:
<form method="post" action="test3.php" name="search_form">
<input type="text" name="search" size=15 maxlength=15 placeholder = "Gene Symbol"/>
<select name="table[]" id = "table[]" size = "0" multiple>
<option selected="selected"></option>
<option value="infla_info">Inflammation</option>
<option value="diet_info">diet</option>
<option value="obesity_info">obesity</option>
<option value="stress_info">stress</option>
<option value="athero_info">atherosclerosis</option>
<option value="retino_info">Diabetic Retinopathy</option>
<option value="nephro_info">Diabetic Nephropathy</option>
<option value="neuro_info">Diabetic Neuropathy</option>
</select>
<input type="Submit" name="Submit" value="Gene Search"/>
这里的value =表名,对于它正在工作的每个表,对于多个表也可以工作,但是当它选择它的时间完全失败时。 我已经添加了select all选项,但因为它不适用于提取。
任何人都可以建议我如何在mysql数据库的所有表中选择搜索词?这对我选择的所有选项都是有益的。第二,选择所有选项的值=“”应该是什么。
case "infla_info":
//echo "<h1> Inflammation </h1>";
$sql = mysqli_query($con, "select * from infla_info where Gene_symbol = '$search'");
$num_row=$sql->num_rows;
if ($num_row == 0)
{
echo "<font color = 'red'>Gene not found in Inflammation.</font>";
}
else
{
for($i=0;$i<$num_row;$i++)
{
$result=mysqli_fetch_assoc($sql);
echo "
<table border='0', width='1000', align='center'>
<tr>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Theme</font></th>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Locus_Id</font></th>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Gene_Symbol</font></th>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Gene_Name</font></th>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Synonyms</font></th>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Chromosome</font></th>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Gene Summary</font></th>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Homologene_Id</font></th>
</tr>
";
echo "<tr bgcolor = '#D3D3D3'>";
echo "<td align=center>";
echo 'Inflammation';
echo "</td>";
$strName2 = $result["Locus_id"];
$strLink2 = "<a href = 'infla_gene_go.php?gene_id=" . $result['Locus_id'] . "'>" . $strName2 . "</a>";
echo "<td align=center><font color = 'black'>" . $strLink2 . "</font></td>";
$strName1 = $result["Gene_symbol"];
$strLink1 = "<a href = 'infla_gene_symbol.php?gene_symbol=" . $result['Gene_symbol'] . "'>" . $strName1 . "</a>";
echo "<td align=center><font color = 'black'>" . $strLink1 . "</font></td>";
echo "<td align=center><font color = 'black'>" . $result['Gene_name'] . "</font></td>";
echo "<td align=center><font color = 'black'>" . $result['Synonymns'] . "</font></td>";
echo "<td align=center><font color = 'black'>" . $result['Chromosome_no'] . "</td>";
echo "<td height='50px'><div style='height:200px; overflow:scroll;'><font color = 'black'>" . $result['Gene_summary'] . "</font></div></td>";
$strName = $result["Homologene_id"];
$strLink = "<a href = 'infla_homologene.php?homologene_id=" . $result['Homologene_id'] . "'>" . $strName . "</a>";
echo "<td align=center>" . $strLink . "</td>";
echo "</tr>";
}
}
break;
case "stress_info":
$sql = mysqli_query($con, "select * from stress_info where Gene_symbol = '$search'");
$num_row=$sql->num_rows;
if ($num_row == 0)
{
echo "<font color = 'red'>Gene not found in Stress.</font>";
}
else
{
for($i=0;$i<$num_row;$i++)
{
$result=mysqli_fetch_assoc($sql);
echo "<table border='0', width='1000', align='center'>
<tr>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Theme</font></th>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Locus_Id</font></th>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Gene_Symbol</font></th>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Gene_Name</font></th>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Synonyms</font></th>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Chromosome</font></th>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Gene Summary</font></th>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Homologene_Id</font></th>
</tr>";
echo "<tr bgcolor = '#D3D3D3'>";
echo "<td align=center>";
echo 'Stress';
echo "</td>";
$strName2 = $result["Locus_id"];
$strLink2 = "<a href = 'stress_gene_go.php?gene_id=" . $result['Locus_id'] . "'>" . $strName2 . "</a>";
echo "<td align=center>" . $strLink2 . "</td>";
$strName1 = $result["Gene_symbol"];
$strLink1 = "<a href = 'stress_gene_symbol.php?gene_symbol=" . $result['Gene_symbol'] . "'>" . $strName1 . "</a>";
echo "<td align=center>" . $strLink1 . "</td>";
echo "<td align=center>" . $result['Gene_name'] . "</td>";
echo "<td align=center>" . $result['Synonymns'] . "</td>";
echo "<td align=center>" . $result['Chromosome_no'] . "</td>";
echo "<td height='50px'><div style='height:200px; overflow:scroll;'>" . $result['Gene_summary'] . "</div></td>";
//$strName = $result['FirstName'] . " " . $result['LastName']
$strName = $result["Homologene_id"];
// Create a link to person.php with the id-value in the URL
// $strLink = "<a href = 'person.php?id = " . $result['id'] . "'>" . $strNavn . "</a>";
$strLink = "<a href = 'stress_homologene.php?homologene_id=" . $result['Homologene_id'] . "'>" . $strName . "</a>";
echo "<td align=center>" . $strLink . "</td>";
// echo "<td align=center>" . $result['PMID'] . "</td>";
echo "</tr>";
break; //This counts the number or results - and if there wasn't any it gives them a little message explaining that
}
}
以上是从表中获取数据的代码。 请各位朋友帮帮忙,马老板要杀了我...... 提前完成。
答案 0 :(得分:0)
可能有多种方法可以做到这一点。你的问题我不清楚,如果我错了,请纠正我。
如果要从多个表中选择列,可以尝试使用UNION
运算符。在您的选择框中添加“全部”选项。
<option value='all'>All</option>
首先检查选项值,如果它等于'all',只需使用UNION
运算符来结合不同SQL查询的结果。
例如,我有2个表:
表1
-----------------------
id | name | age |
-----------------------
1 | boo | 12 |
-----------------------
2 | boom | 13 |
-----------------------
表2
-----------------------
id | name | age |
-----------------------
1 | rofl | 14 |
-----------------------
2 | lol | 15 |
-----------------------
现在SELECT * FROM table1 UNION SELECT * FROM table2
会产生如下内容:
-----------------------
id | name | age |
-----------------------
1 | boo | 12 |
-----------------------
2 | boom | 13 |
-----------------------
1 | rofl | 14 |
-----------------------
2 | lol | 15 |
-----------------------
基本上你只需要检查选项值,并且它是否等于使用UNION
运算符的那些SQL查询的所有结果。