2017-01-16 99 views
1

我試圖從SQL查詢中顯示多行數據。我能夠構建引用,以便表目前顯示一行,但想知道如何使用相同的表結構顯示所有行。PHP/HTML返回Oracle數據庫中的所有行查詢

<?php 
    include('connect.php'); 
    oci_execute($sql);  
    while ($row = oci_fetch_array ($sql)) { 
     $pt = $row[0]; 
     $eas = $row[1]; 
     $shd = $row[2]; 
     $epc = $row[3]; 
     $tpc = $row[4]; 
     $uid = $row[5]; 
    } 
?> 

使用下面

<table class="table" id="aut"> 
    <tr> 
     <th>Pt</th> 
     <th>Eas</th> 
     <th>Cs</th> 
     <th>Or</th> 
     <th>Pr</th> 
     <th>Ct?</th> 
     <th>Al</th> 
    </tr> 
    <tr> 
     <td><input type="text" name="Pt" value="<?php echo $pt; ?>" class="form-control" readonly=""></td> 
     <td><input type="text" name="Eas" value="<?php echo $eas; ?>" class="form-control" readonly=""></td> 
     <td><input type="text" name="Cs" value="<?php echo $tpc; ?>" class="form-control" readonly=""></td> 
     <td><input type="text" name="Or" value="<?php echo $shd; ?>" class="form-control" readonly=""></td> 
     <td><input type="text" name="Pr" value="<?php echo $usd; ?>" class="form-control" readonly=""></td> 
     <td><input type="text" name="Al" value="<?php echo $epc; ?>" class="form-control" disabled></td> 
    </tr> 
</table> 

回答

1

表的結構它會是這樣的:

<table class="table" id="aut"> 
     <tr> 
      <th>Pt</th> 
      <th>Eas</th> 
      <th>Cs</th> 
      <th>Or</th> 
      <th>Pr</th> 
      <th>Ct?</th> 
      <th>Al</th> 
     </tr> 
<?php 

    include('connect.php'); 

    oci_execute($sql);  

    while ($row = oci_fetch_array ($sql)) { 

    $pt  = $row[0]; 
    $eas = $row[1]; 
    $shd = $row[2]; 
    $epc = $row[3]; 
    $tpc = $row[4]; 
    $uid = $row[5]; 

?> 


    <tr> 
     <td><input type="text" name="Pt" value="<?php echo $pt; ?>" class="form-control" readonly=""></td> 
     <td><input type="text" name="Eas" value="<?php echo $eas; ?>" class="form-control" readonly=""></td> 
     <td><input type="text" name="Cs" value="<?php echo $tpc; ?>" class="form-control" readonly=""></td> 
     <td><input type="text" name="Or" value="<?php echo $shd; ?>" class="form-control" readonly=""></td> 
     <td><input type="text" name="Pr" value="<?php echo $usd; ?>" class="form-control" readonly=""></td> 
     <td><input type="text" name="Al" value="<?php echo $epc; ?>" class="form-control" disabled></td> 
    </tr> 

<?php 

} 
?> 
</table> 
+0

這工作,從查詢中獲取剩餘的行謝謝。 –

+0

我之前做錯了,嘗試更新的代碼。 – Phiter

0

您的代碼需要大量的優化,如果使用DB調用和輸出同樣的文件,將輸出放在一個變量中,然後回顯最終結果如下:

<?php 
include('connect.php'); 
oci_execute($sql); 

$table = '<table class="table" id="aut"> 
    <tr> 
     <th>Pt</th> 
     <th>Eas</th> 
     <th>Cs</th> 
     <th>Or</th> 
     <th>Pr</th> 
     <th>Ct?</th> 
     <th>Al</th> 
    </tr>'; 

while ($row = oci_fetch_array($sql)) { 

    $table .= '<tr> 
    <td><input type="text" name="Pt" value="' . $row[0] . '" class="form-control" readonly=""></td> 
    <td><input type="text" name="Eas" value="' . $row[1] . '" class="form-control" readonly=""></td> 
    <td><input type="text" name="Cs" value="' . $row[2] . '" class="form-control" readonly=""></td> 
    <td><input type="text" name="Or" value="' . $row[3] . '" class="form-control" readonly=""></td> 
    <td><input type="text" name="Pr" value="' . $row[4] . '" class="form-control" readonly=""></td> 
    <td><!-- What happened to Ct? --></td> 
    <td><input type="text" name="Al" value="' . $row[5] . '" class="form-control" disabled></td> 
</tr>'; 

} 

$table = '</table>'; 

echo $table; 
相關問題