使用php从oracle数据库显示多行

时间:2015-10-06 04:43:11

标签: php oracle

我试图用PHP显示Oracle表中的多行。 以下是我的代码:

<?php
include("dbconnect.php"); 
$personcon=$conn;

$surname = $_POST['Surname'];   
$suburb = $_POST['Suburb'];
$state = $_POST['State'];
$discipline = $_POST['Discipline'];
$companyname = $_POST['CompanyName'];
$rank = $_POST['Rank'];
$role = $_POST['Role'];
$yearsexperience = $_POST['YearsExperience'];
$recentproject = $_POST['RecentProject'];
$sellrate = $_POST['SellRate'];
$projectnumber = $_POST['ProjectNumber'];
$tendernumber = $_POST['TenderNumber'];

$query = "SELECT CP.ROLE AS CURRENT_ROLE , CP.SURNAME, CP.FIRSTNAME, CP.COMPANY,CC.COMPANYNAME AS CONSULTANT_COMPANY, CP.YEARSEXPERIENCE AS EXPERIENCE_IN_YEAR, CP.QUALIFICATION, D.PRINCIPLEDISCIPLINE, D.SUBDISCIPLINE1, D.SUBDISCIPLINE2, D.SUBDISCIPLINE3, D.SUBDISCIPLINE4, D.SUBDISCIPLINE5, D.SUBDISCIPLINE6,  D.SUBDISCIPLINE7,  D.SUBDISCIPLINE8,  L.SUBURB, L.STATE, L.COUNTRY FROM CONSULTANTPERSONNEL CP, LOCATION L, ONSULTANTPERSONNEL_DISCIPLINE N, DISCIPLINE D, CONSULTANTCOMPANY CC, CONTRACTS C, PROJECTS P, TENDERS T, FEEBASIS F WHERE CP.LOCATIONID = L.LOCATIONID AND CP.CONSULTANTPERSONALID = N.CONSULTANTPERSONALID AND N.DISCIPLINID = D.DISCIPLINID AND CP.CONSULTANTCOMPANYID = CC.CONSULTANTCOMPANYID AND CP.CONTRACTID = C.CONTRACTID AND C.FEECODE = F.FEECODES AND C.PROJECTNUMBER = P.PROJECTNUMBER AND C.TENDERNUMBER = T.TENDERNUMBER AND LOWER(CP.SURNAME) LIKE LOWER('%".$surname."%') AND LOWER(L.SUBURB) LIKE LOWER('%".$suburb."%') AND LOWER(L.STATE) LIKE LOWER('%".$state."%') AND LOWER(D.PRINCIPLEDISCIPLINE) LIKE LOWER('%".$discipline."%') AND LOWER(CC.COMPANYNAME) LIKE LOWER('%".$companyname."%') AND LOWER(CP.RANK) LIKE LOWER('%".$rank."%') AND LOWER(CP.ROLE) LIKE LOWER('%".$role."%') AND LOWER(P.PROJECTNAME) LIKE LOWER('%".$recentproject."%') AND LOWER(P.PROJECTNUMBER) LIKE LOWER('%".$projectnumber."%') AND LOWER(T.TENDERNUMBER) LIKE LOWER('%".$tendernumber."%')";

$SQL = oci_parse($personcon, $query);
oci_execute($SQL);
$results = array();
$numRows = oci_fetch_all($SQL, $results, null, null, OCI_FETCHSTATEMENT_BY_ROW);

        if($numRows > 0){       
        echo "<p> <table border=1>\n";
            //Print the headings
            echo "<tr>\n";
                foreach($results[0] as $index=>$value)
                    echo "<th>$index</th>\n";
            echo "</tr>\n";

            echo "<tr>\n";
            foreach($results as $row)
                foreach($row as $index=>$value)
                    echo "<td>$value</td>\n";
            echo "</tr>\n";
        echo "</table>\n </p>";

        oci_close($personcon);
        } else {
            echo "<tr> The search you enter is not in the database.";
        }
?>  

我可以检索我想要的数据但不是逐行显示,而是显示一行中的所有数据。

任何想法如何解决这个问题?感谢

0 个答案:

没有答案