PHP dynamic HTML table using SQL -
background
i using below code generate html table based on sql results.
code
$stid = oci_parse($conn, " select * ( select orders.order_no, orders.porder_no, orders.date, order_totals.value orders, order_totals orders.order_no = order_totals.order_no , orders.account_no = '" . $_session['session_account'] . "' order orders.order_no desc ) rownum <= 15 "); oci_execute($stid); echo "<table class='table'> <thread> <tr> <th>order no</th> <th>purchase order no</th> <th>date</th> <th>value</th> </tr> </thread> <tbody>"; while ($row = oci_fetch_array($stid, oci_num)) { echo "<tr>"; echo '<td><a href="view.php?id=' . $row['0'] . '">' . $row['0'] . '</a></td>'; echo "<td>" . $row['1'] . "</td>"; echo "<td>" . $row['2'] . "</td>"; echo "<td>" . $row['3'] . "</td>"; echo "</tr>"; unset($row); } echo "</tbody> </table>";
question
is possible make html table generation part in code more dynamic, if need add additional column example can ammend sql part in code?
i had idea set column headings using as
in sql , can amend sql use as
show real column headings want example
select orders.order_no "order no" , orders.porder_no "purchase order no" , orders.date "date" , order_totals.value "total"
but html table part, there method print columns , rows dynamically, maybe create function printtable
handle any table?
the $row var array can loop on too. since want treat first field differently write out before loop , start loop @ 1.
while ($row = oci_fetch_array($stid, oci_num)) { echo "<tr>"; echo '<td><a href="view.php?id=' . $row[0] . '">' . $row[0] . '</a></td>'; ( $ii = 1; $ii < count($row); $ii++ ) { echo "<td>" . $row[$ii] . "</td>"; } echo "</tr>"; }
i don't know unset($row) for, left out.
Comments
Post a Comment