Php 为什么oci_fetch_数组($stid)不返回oracle数据库表的第一行

Php 为什么oci_fetch_数组($stid)不返回oracle数据库表的第一行,php,oracle,Php,Oracle,我试图创建一个搜索表单,从oracle数据库返回一些数据,除了跳过表的第一行之外,它工作正常。 我使用了以下代码: enter code here if(isset($_POST['search']) && !empty($_POST["search_box"])){ $name=$_POST['search_box']; $sql='SELECT deejays.name,available_dates.data, available_dates.venue,available

我试图创建一个搜索表单,从oracle数据库返回一些数据,除了跳过表的第一行之外,它工作正常。 我使用了以下代码:

enter code here
if(isset($_POST['search']) && !empty($_POST["search_box"])){
$name=$_POST['search_box'];
$sql='SELECT deejays.name,available_dates.data, available_dates.venue,available_dates.location FROM deejays,available_dates';
$sql .=" WHERE deejays.name ='{$name}'";
$sql .=' AND pk_id=fk_id';
$verify="SELECT  deejays.name FROM deejays WHERE deejays.name ='{$name}'";
$stid = oci_parse($conn,$sql );
oci_execute($stid);
if (oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)){
echo "<table width=\"100%\" align=\"center\" cellpadding=\"5\" cellspacing=\"5\">
<tr class=\"source\">
    <td colspan=3 align=\"center\"><h1>The facebook tour dates for ".$name." are:</h1></td>
</tr>
<tr align=\"center\" class=\"source1\">

    <td><strong>DATA</strong></td>
    <td><strong>VENUE</strong></td>
    <td><strong>LOCATION</strong></td>
</tr>";?>
<?php while($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)){ ?>
<tr align="center" class="rows">

    <td ><?php echo $row['DATA'];?></td>
    <td ><?php echo $row['VENUE'];?></td>
    <td ><?php echo $row['LOCATION'];?></td>
</tr>
<?php } ?>
</table>
<?php } else {
            $stid = oci_parse($conn,$verify );
            oci_execute($stid);
            if (oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS))
             { echo "This artist hasn't records on facebook/bandsintown<br>  
enter code here
预期结果是:

真正的结果是:

第二幅图显示跳过了第一行,我如何解决这个问题?提前感谢我的评论,oci_fetch_数组将返回一个包含查询的下一个结果集行的数组。这意味着每次调用它时,光标都会移动到下一行。我有两个建议

首先

执行oci_后,将所有结果加载到数组中。如果数组有行,则对其进行计数

oci_execute($stid);
$result = array();

while($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS))
{
    $array[] = $row;
}
//check if result is not empty
if (count($result)) {
   //the table part here.
}
当您想在html表中显示它时,可以使用foreach循环来迭代数组并构建数组

而建筑将与第一个相同


另一种方法是使用缓冲查询。但这取决于许多因素。

第一次调用ifoci\u fetch\u array$stid,OCI\u ASSOC+OCI\u RETURN\u NULLS将返回第一行并将光标移动到下一行。那么,您的while循环将从第二行开始。我如何使它再次从第一行开始?不要。只需在所有行上迭代一次。在第一行中,检查一个布尔值,它跟踪您是否已经打印了表头。然后打印表格标题。或者不是。
<?php foreach($result as $row) { ?>

    <tr align="center" class="rows">
        <t ><?php echo $row['DATA'];?></td>
        <td><?php echo $row['VENUE'];?></td>
        <td><?php echo $row['LOCATION'];?></td>
    </tr>
<?php } ?>
oci_execute($stid);
//$result will have all the result of the current query
$count = oci_fetch_all($stid, $result);

if ($count) {
//table part here
}