我的问题是我有一个链接到Oracle中多个表的网站。我目前有PHP代码检查分配给变量的用户输入以查找表中的数据,然后是oci_fetch_row语句,用于获取数据匹配的行。这工作正常,但如果某些值相同,我无法找到如何从表中输出多行?
目前,它抓取的一行被放入一个简单的HTML表格中。
有关如何获取数据匹配并输出到表的所有行的任何帮助都将受到赞赏。
我的代码是:
$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>";
}
答案 0 :(得分:1)
将oci_fetch_row语句放入while循环中。 OCI Fetch Array代码示例
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>";
答案 1 :(得分:-1)
Html索引: 使用超链接引用:
<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);
?>
html表单代码:
<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>