1

I am trying to display multiple rows of data from a SQL query. I was able to build the reference so that table currently shows one row but was wondering how to show all rows using the same table structure.

 <?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]; 
    }
?>

Using the table structure below

<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>

2 Answers 2

1

It'd be something like this:

<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>
Sign up to request clarification or add additional context in comments.

1 Comment

That worked to get the reamining rows from the query Thank you.
0

Your code needs a lot of optimization, if you use DB calls and output in the same file, it's always wiser to put the output in a variable and only then echo the end result something like this:

<?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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.