- print_r: documentation ( source)
- json_encode: documentation ( source)
<?php
$table = 'ILRL';
$requestedWO = $_GET['wo'];
// Grab last 20 workorders
$query = $bd->prepare("SELECT DISTINCT workorder FROM $table Order By date_time DESC LIMIT 20");
try {
if(!$query->execute())
die(print_r($bd->errorInfo()));
$woList = $query->fetchAll(PDO::FETCH_OBJ);
} catch (Exception $e) { echo $e->getMessage(); }
// wo results
if( empty($requestedWO) )
$requestedWO = $woList[0]->workorder;
$tableheader = false;
$query = $bd->prepare("SELECT * FROM $table WHERE workorder=$requestedWO ORDER BY date_time DESC LIMIT 1000");
try {
if(!$query->execute())
die(print_r($bd->errorInfo()));
echo "<table class='striped responsive-table'>";
while($row = $query->fetch(PDO::FETCH_ASSOC))
{
if($tableheader == false) {
echo '<thead><tr>';
foreach($row as $key=>$value) {
echo "<th>{$key}</th>";
}
echo '</tr></thead><tbody>';
$tableheader = true;
}
echo "<tr>";
foreach($row as $value) {
echo "<td>{$value}</td>";
}
echo "</tr>";
}
echo "</tbody></table>";
} catch (Exception $e) { echo $e->getMessage(); }
?>
<script type="text/javascript">
var woListFromSQL = <?php print(json_encode($woList)); ?>;
</script>