Reputation: 37
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>
Upvotes: 1
Views: 1055
Reputation: 14992
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>
Upvotes: 1
Reputation: 8020
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;
Upvotes: 0