我目前正在创建一个数据库,其中包含用于一般基于文本的搜索的搜索框并以表格格式进行搜索。实际数据是17列,但搜索结果只给出5列。 5列中的一列提供了链接到进一步页面的链接,该页面提供来自其余列的所有数据。从获取的数据显示5列在我的网页,PHP代码 -php中未定义的偏移量错误php中的一半爆炸阵列
<?php
$con = new mysqli("localhost","root","","project");
if(!$con){
die("Database not found" .$con->connect_error);
}
$sw=$_POST['query'];
$sql= "SELECT * FROM ps1 WHERE Entry like '%".$sw."%' OR Prot_name like '%".$sw."%' OR Gene_name like '%".$sw."%' OR Function like '%".$sw."%' OR Org_name like '%".$sw."%'";
$res=mysqli_query($con,$sql);
$number=mysqli_num_rows($res);
echo "<h2>".$number."hits found</h2>";
echo"<br><table class='col3' border=1>
<tr><th>Uniprot ID
</th><th>Entry Name
</th><th>Protein name
</th><th>Gene name
</th><th>Sequence length
</th><th>Organism name
</th><th>Sequence
</th></tr>";
if(mysqli_num_rows($res) > 0)
{
while($row=mysqli_fetch_assoc($res))
{
echo "<tr>";
echo "<td><a href=\"Fullentry.php?rowid=id".$row['Entry']."|".$row['Entry_name']."|".$row['Prot_name']."|".$row['Gene_name']."|".$row['Taxonomic_lineage']."|".$row['Org_name']."|".$row['Length']."|".$row['Subcellular_loc']."|".$row['Intramembrane']."|".$row['Topology']."|".$row['Transmembrane']."|".$row['Function']."|".$row['GO']."|".$row['Cross_ref']."|".$row['Pubmed_ID']."|".$row['Interpro']."\">ENTRY</a></td>";
echo "<td>" . $row['Entry_name'] . "</td>";
echo "<td>" . $row['Prot_name'] . "</td>";
echo "<td>" . $row['Gene_name'] . "</td>";
echo "<td>" . $row['Length'] . "</td>";
echo "<td>" . $row['Org_name'] . "</td>";
echo "<td><a href=\"Sequence.php?rowid=" . $row['Entry']."|".$row['Sequence'] . "\">FASTA SEQUENCE</a></td>";
echo "</tr>";
}
}
基本上我在这里做的是,我已经使用了|
运营商拆分所有从表中的列并压缩成一个单一的href
链接。下一个页面,显示数据从链接 -
<?php
/*Get the previous page data into the variable */
$row = $_GET['rowid'];
/*Explode using the marker*/
$row = explode("|", $row);
/*Check if all indices are present*/
print_r($row);
/*Printing all the data from the previous page*/
echo "<h3>Entry for".$row[0]."</h3>";
echo "<h4>Uniprot ID</h4>";
echo "<h4>".$row[0]."<h4>";
echo "<br><h4>Entry name from Uniprot</h4>";
echo "<h4>".$row[1]."<h4>";
echo "<br><h4>Protein name</h4>";
echo "<h4>".$row[2]."</h4>";
echo "<br><h4>Gene name</h4>";
echo "<h4>".$row[3]."</h4>";
echo "<br><h4>Taxonomic Lineage</h4>";
echo "<h4>".$row[4]."</h4>";
echo "<br><h4>Organism name</h4>";
echo "<h4>".$row[5]."</h4>";
echo "<br><h4>Sequence length</h4>";
echo "<h4>".$row[6]."</h4>";
echo "<br><h4>Subcellular location</h4>";
echo "<h4>".$row[8]."</h4>";
echo "<br><h4>Intramembrane</h4>";
echo "<h4>".$row[9]."</h4>";
echo "<br><h4>Topology</h4>";
echo "<h4>".$row[10]."</h4>";
echo "<br><h4>Transmembrane</h4>";
echo "<h4>".$row[11]."</h4>";
echo "<br><h4>Function</h4>";
echo "<h4>".$row[12]."</h4>";
echo "<br><h4>GO-terminologies</h4>";
echo "<h4>".$row[13]."</h4>";
echo "<br><h4>Cross references</h4>";
echo "<h4>".$row[14]."</h4>";
echo "<br><h4>Pubmed ID</h4>";
echo "<h4>".$row[15]."</h4>";
echo "<br><h4>Interpro ID</h4>";
echo "<h4>".$row[16]."</h4>";
echo "<br><h4>Protein Sequence</h4>";
echo "<h3>".$row[7]."</h3>";
?>
此页是什么,它发现|
并给出了索引与爆炸功能的帮助。 但我的问题是我只得到指数的前4个值。我想要的是我需要显示从第一页传递的早期值中的所有17个值。任何帮助将不胜感激,为什么只有第一个值被解析,为什么不休息?而且如果有任何解决方案,它将被提升。先谢谢你! PS - 我经历了很多PHP文档以及几乎所有与'Undefined offset error in php'有关的问题,但是我找不到与我的问题有关的任何问题。如果有任何重复,我想道歉。
你为什么这样做?将你的字段添加为查询字符串'?rowid = id&field1 = row1&field2 = row2 ....'等等,或者简单地发送你的id,然后在另一个页面中做一个简单的查询来获取具有该id的行。 – hassan
@hassan - 请您详细说明这种方法,因为我对此很新颖。我实际上不知道如何重叠mysql查询,也就是说,它已经被用来获取html页面上的表格数据。而从表格数据中,我不知道如何实际获取其余的列。 – Srk
@hassan - 任何文档的参考也将不胜感激! – Srk