我想知道我的代码中缺少什么。
我有这个HTML代码:
<html>
<head>
<title>Human gene catalog</title>
</head>
<body>
<h1>Reference sequence and Gene Ontology catalog</h1>
<p>
<b>1.Search for a gene:</b>
<form action=prueba.php method=post>
<select name=organism>
<option value=1>Human</option>
<option value=2>Mouse</option>
<option value=3>Zebrafish</option>
<option value=4>Fruit fly</option>
</select>
<label>Please select a gene:</label>
<br/>
<input type=text name=gene>
<br/><br/>
<input type=submit name=submit value=Submit>
</form>
</p>
</html>
这段PHP代码:
<?php
$gene = $_POST["gene"];
$specie = $_POST["organism"];
$enlace = mysqli_connect("localhost","root","******","refGene");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if ($specie == 1) {
mysqli_select_db($enlace,"refGene_human");
} elseif ($specie == 2) {
mysqli_select_db($enlace,"refGene_mouse");
} elseif ($specie == 3) {
mysqli_select_db($enlace,"refGene_zebrafish");
} elseif ($specie == 4) {
mysqly_select_db($enlace,"refGene_fruitfly");
} else {
echo "The gene is not in database";
}
$result = mysqli_query($enlace,"select * from (here I dont know what to put,if with one specie, here I put the name of the table) where name2 like '%$gene%'");
echo "<h1>Gene Reference Results</h1>";
echo "<table 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);
基本上,我想要实现的是,在HTML文档中选择一个物种和一个基因名称,它将带您进入PHP,在这里,根据物种(1,2,3,4)的值,它选择了相应的数据库。 ,然后对其进行查询以找到一些信息。
我有正确的代码可以使它工作,但是只需要一个种类,而在HTML中没有选择列表,而在PHP中没有if语句,但是我想使它在多个中工作。
我认为我应该在PHP的if语句之前声明一些变量,然后查询该变量,这应该告诉查询函数选择哪个表。
但是我不知道什么是正确的语法。
if ($specie == 1) {
mysqli_select_db($enlace,"refGene_human");
$database = 'refGene_human';
}
elseif ($specie == 2) {
mysqli_select_db($enlace,"refGene_mouse");
$database = 'refGene_mouse';
}
elseif ($specie == 3) {
mysqli_select_db($enlace,"refGene_zebrafish");
$database = 'refGene_zebrafish';
}
elseif ($specie == 4) {
mysqly_select_db($enlace,"refGene_fruitfly");
$database = 'refGene_fruitfly';
}
else {
echo "The gene is not in database";
}
$result = mysqli_query($enlace,"select * from '$database' where name2 like '%$gene%'");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句