My issue is I have a website that is linking to multiple tables in Oracle. I currently have PHP code that checks user input assigned to a variable to find data in a table, then the oci_fetch_row statement that grabs the row where the data matches. This works fine but I cannot find how to output more than one row from a table if some values are the same?
Currently the one row it grabs is put into a simple HTML table.
Any help in to how to fetch all rows that the data matches and output to table would be appreciated.
My code is:
$userfeedback = "SELECT * FROM ASSET_FEEDBACK WHERE USER_EMAIL = '$userEmail' ORDER BY FEEDBACK_DATE";
$stmt3 = oci_parse($conn, $userfeedback);
if(oci_execute($stmt3))
{
$row=oci_fetch_row($stmt3) ;
print"<h2 id='title'>This Users Feedback</h2>";
"<table border='2'>";
print"<tr><td><p>Feedback ID:</td><td>$row[0]</td></tr>";
print"<tr><td>Asset ID:</td><td>$row[1]</td></tr>";
print"<tr><td>Feedback:</td><td>$row[3]</td></tr>";
print"<tr><td>Date added:</td><td>$row[4]</td></tr>";
print"</table></br>";
}
Put the oci_fetch_row statement into a while loop. OCI Fetch Array for a code sample
print"<h2 id='title'>This Users Feedback</h2>";
print"<table border='2'>";
while ($row=oci_fetch_row($stmt3))
{
print"<tr><td><p>Feedback ID:</td><td>$row[0]</td></tr>";
print"<tr><td>Asset ID:</td><td>$row[1]</td></tr>";
print"<tr><td>Feedback:</td><td>$row[3]</td></tr>";
print"<tr><td>Date added:</td><td>$row[4]</td></tr>";
}
print"</table></br>";
Html index: Use hyperlink reference:
<a href="http://localhost/yourpath.php?opt=1>Show table</a>
Conect to database and show table:
<?php
echo $opt=$_GET['opt'];
$connection=OCILogon("user","password");
if($opt=='1') /*if u have a menu with other html*/
{
$ctab =OCIParse($connection,"SELECT * FROM table");
OCIExecute($ctab)
echo "<table>";
echo "<tr>";
echo "<th>ID</th>;
....all your table header
echo "</tr>";
while(OCIFetch($ctab))
{ $id = OCIResult($ctab,"ID");
.........
print( "<tr>".
"<td>$id</td>".
........
"</tr>");
}
elseif($opt='2') /*if you have a form , to get values and insert into table*/
{ echo $FirVal=$_POST["firval"];
$SecVal=$_POST["secval"];
echo $LastVal=$_POST["lastval"];
$ctab2=OCIParse($connect,"insert into table values($firval , '$secval', $lastval)");
OCIExecute($ctab2);
}
OCIFreeStatement($ctab2);
OCIFreeStatement($ctab);
OCILogOff($connection);
?>
Code for html form:
<form method="POST" action="http://localhost/phppath.php?opt=2">
Firstval:<input type="text" name="FirVal" size=8><br>
...........
<input type="SUBMIT" value="Add Values">
<input type="Reset" value ="Reset">
</form>