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.