static function fetch($query, $params = NULL, $column = NULL)
{
if (!($statement = DB::query($query, $params))) {
return;
}
// Return an array of records
if ($column === NULL) {
return $statement->fetchAll();
}
// Fetch a certain column from all rows
return $statement->fetchAll(\PDO::FETCH_COLUMN, $column);
}
<?php #DB use DByte\DB; DB::$c = $pdo; echo "\n\n<div class=\"panel panel-primary\">\n\t<div class=\"panel-heading\">\n\t\t<h3 class=\"panel-title\">Sensors</h3>\n\t</div>\n <div class=\"panel-body\">\n\n\t<strong>Add sensors to the database</strong>\n\t\t<form action=\"include/add_sensors.php\" method=\"POST\" id=\"AddSensors\">\n\t\t\t<p>Recorder:<br><input type=\"text\" name=\"Recorder\" maxlength=\"100\" size=\"40\"><br>\n\t\t\tMicrophone: <br><input type=\"text\" name=\"Microphone\" maxlength=\"80\" size=\"40\"><br>\n\t\t\tNotes of the sensor: <br><input type=\"text\" name=\"Notes\" maxlength=\"255\" size=\"40\"><br>\n\t\t\t<button type=\"submit\" class=\"btn btn-primary\"> Add sensor </button>\n\t\t</form>"; #Sensors in the db: echo "<hr noshade>"; $no_sensors = DB::column('SELECT COUNT(*) FROM `Sensors`'); if ($no_sensors == 0) { echo "<p>There are no sensors in the system."; } else { $rows = DB::fetch('SELECT * FROM `Sensors` ORDER BY `SensorID`', array(TRUE)); echo "<p>The system has the following " . count($rows) . " sensors:\n\t\t<table>"; echo "<tr>\n\t\t\t<td>Sensor ID</td>\n\t\t\t<td> </td>\n\t\t\t<td>Recorder</td>\n\t\t\t<td> </td>\n\t\t\t<td>Microphone</td>\n\t\t\t<td> </td>\n\t\t\t<td>Notes</td>\n\t\t\t<td> </td>\n\t\t\t<td>Edit</td>\n\t\t</tr>\n"; foreach ($rows as $row) { # for ($i = 0; $i < $nrows; $i++) { #$row = mysqli_fetch_array($result); #extract($row); echo "<tr>\n\t\t\t\t<td>" . $row->SensorID . "</td>\n\t\t\t\t<td> </td>\n\t\t\t\t<td>" . $row->Recorder . "</td>\n\t\t\t\t<td> </td>\n\t\t\t\t<td>" . $row->Microphone . "</td>\n\t\t\t\t<td> </td>\n\t\t\t\t<td>" . $row->Notes . "</td>\n\t\t\t\t<td> </td>\n\t\t\t\t<td><a href=\"sensor_edit.php?SensorID=" . $row->SensorID . "\"><img src=\"images/pencil.png\"></td>\n\t\t\t</tr>\n"; } echo "</table>"; } echo "</div></div>";