0

I am currently creating a database which consists of a search box for general text-based searches and gives the search in a tabular format. The actual data is of 17 columns but the search result gives only 5 columns. One column from the 5 columns provides a link to a further page which gives all the data from the rest of the columns. The php code for my page displaying 5 columns from fetching the data is -

 <?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>";
    }
}

Basically what I have done here is, I have used the | operator to split all the columns from the table and compressed into a single href link. The next page which shows the data from the link is -

<?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>";

?>

What this page does is, it finds | and gives indexing with the help of explode function. But my problem is I get only the first 4 values from the indices. What I want is I need to display all the 17 values from the earlier passed values from the first page. Any help would be appreciated as to why only the first values are being parsed and why not the rest? And also if there is any solution, it will be aprreciated. Thank you in advance! PS - I went through a lot of PHP-documentation as well as almost all the questions relating to the 'Undefined offset error in php', but I could not find any problem relating to my problem. If there is any duplicate, I would like to apologize.

Srk
  • 69
  • 2
  • 8
  • why do you do like this? add your fields as a query string `?rowid=id&field1=row1&field2=row2....` and so on, or simply send your id then make a simple query in the other page to fetch the row which have that id. – hassan Apr 25 '17 at 07:44
  • @hassan - Can you please elaborate on this method, because I am pretty new to this. I actually have no idea how I can overlap a mysql query that is, it has been already used once to get the table data which is on the html page. And from that table data, I have no idea how to actually fetch the rest of the columns. – Srk Apr 25 '17 at 07:51
  • @hassan - Any documentation for reference will also be appreciated! – Srk Apr 25 '17 at 07:52
  • Take a look at PHP manual, and some basics tutorials – Gntem Apr 25 '17 at 07:53
  • @Mr.Phoenix - Okay will do.. – Srk Apr 25 '17 at 11:12
  • But can someone actually comment on the functionality or the error because I cannot really figure out why the error is there. – Srk Apr 25 '17 at 11:13

1 Answers1

1

Refering to the first snippet you posted, the $_GET receiving URL has limitations on the character string length you pass. Make sure you should not exceed the limit. Please refer the below link for more clarification. hope it might help you.

Max size of URL parameters in _GET

P.S - If you can show me the whole code of your first snippet, may be I can help you more.

Edited here-

First of all I would appreciate your efforts to provide whole code for the first snippet. Use below logic to send an entry to the fullentry.php page.

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

Now, Get the entry value in fullentry.php file and then use below code to fetch the data and displayed on the html.

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

Using the $res object you can simply fetch the data from the database, same as you are doing in first snippet. like- $res['Entry_name'] , $res['Prot_name']

Hope this solution might help you. kindly click on this answer is useful.

Community
  • 1
  • 1
zlogic
  • 70
  • 1
  • 7
  • That is the problem. I am getting the limit exceeded problem because when I tried to print the '$row' before exploding and it shows only half a string. As you requested, I'll edit the question and provide you the whole first snippet code. – Srk Apr 27 '17 at 19:07
  • Awesome answer! A big-big thank you! A very new way of solving my query! – Srk Apr 28 '17 at 11:09