2017-04-25 36 views
0

我目前正在创建一个数据库,其中包含用于一般基于文本的搜索的搜索框并以表格格式进行搜索。实际数据是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'有关的问题,但是我找不到与我的问题有关的任何问题。如果有任何重复,我想道歉。

+0

你为什么这样做?将你的字段添加为查询字符串'?rowid = id&field1 = row1&field2 = row2 ....'等等,或者简单地发送你的id,然后在另一个页面中做一个简单的查询来获取具有该id的行。 – hassan

+0

@hassan - 请您详细说明这种方法,因为我对此很新颖。我实际上不知道如何重叠mysql查询,也就是说,它已经被用来获取html页面上的表格数据。而从表格数据中,我不知道如何实际获取其余的列。 – Srk

+0

@hassan - 任何文档的参考也将不胜感激! – Srk

回答

1

参考您发布的第一个片段,$ _GET接收URL对您传递的字符串长度有限制。确保你不应该超过限制。 请参考以下链接了解更多信息。希望它可以帮助你。

Max size of URL parameters in _GET

P.S - 如果你能告诉我你的第一个片段的整个代码,可能是我可以帮你。

编辑这里 -

首先我会感激你的努力,做第一个片段提供完整的代码。 使用以下逻辑将条目发送到fullentry.php页面。

echo "<td><a href=\"Fullentry.php?rowid=".$row['Entry']."\">ENTRY</a></td>"; 

现在,获取fullentry.php文件中的条目值,然后使用下面的代码来获取数据并显示在html上。

$entry = $_GET['rowid']; 
$sql= "SELECT * FROM ps1 WHERE Entry like '%".$entry."%'"; 
$res=mysqli_query($con,$sql); 

使用$水库对象,你可以简单地从数据库中读取数据,一样的,你在第一个片段做。 like-$ res ['Entry_name'],$ res ['Prot_name']

希望此解决方案可能对您有所帮助。 请点击此答案很有用。

+0

这就是问题所在。我得到了超出限制的问题,因为当我试图在爆炸之前打印'$行'时,它只显示了一半的字符串。按照您的要求,我将编辑该问题并为您提供整个第一段代码。 – Srk

+0

太棒了!非常感谢你!一种解决我的查询的新方法! – Srk