Which database driver you using mysql or mysqli?
good stuff making sure as its more procedural and object oriented..
hehe are those examples i sent helping at all? I built those projects when i began years ago, and reused the methods over and over again, though it always seems i make them more complicated as I build. Over time I try to reduce line count.. lol..never really works that way..
<?php
require 'conn.php';
$time_start = microtime(true);
$printed = false;
$sql = "SELECT * FROM `myTable` ORDER BY id DESC LIMIT 10;";
$result = $db_conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if (!empty($row["RES_pH"])) {
echo "<td>". $row["RES_pH"]. "</td><td>". $row["RES_EC"]. "</td><td>". $row["RES_temp"]. "</td><td>". $row["RES_ph_up_total"]. "</td><td>". $row["RES_ph_down_total"]. "</td><td>". $row["RES_total_in"]. "</td>";
$printed = true;
}
if ($printed === true) {
break;
}
}
} else {
echo "<td>no results</td><td> </td><td> </td><td> </td><td> </td><td> </td>";
}
$time_end = microtime(true);
$time = number_format((($time_end - $time_start) * 1000000), 4);
// "<p>loaded in $time microseconds</p>";
?>
<?php
require 'conn.php';
$time_start = microtime(true);
$print1 = false;
$print2 = false;
$sql = "SELECT * FROM `myTable` ORDER BY id DESC LIMIT 30;";
$result = $db_conn->query($sql);
echo "<tr><td colspan=\"6\"><strong>AREA ONE</strong></td></tr>";
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if (!empty($row["ENV_A1_AT"]) && $print1 === false) {
echo "<tr><td width=\"17%\">Air Temp</td><td width=\"24%\">Air Temp error</td><td width=\"18%\">RH%</td><td width=\"15%\">RH% error</td><td width=\"13%\">CO2</td><td width=\"13%\">CO2 error</td></tr>";
echo "<tr><td>". $row["ENV_A1_AT"]. "</td><td>". $row["ENV_A1_ATE"]. "</td><td>". $row["ENV_A1_RH"]. "</td><td>". $row["ENV_A1_RHE"]. "</td><td>". $row["ENV_A1_CO2"]. "</td><td>". $row["ENV_A1_CO2E"]. "</td></tr>";
echo "<tr><td>Lights</td><td>Light intensity</td><td>Return TDS</td><td>Return temp</td><td colspan=\"2\">Pressure </td></tr>";
echo "<tr><td>". $row["ENV_A1_L"]. "</td><td>". $row["ENV_A1_LI"]. "</td><td>". $row["ENV_A1_TDS"]. "</td><td>". $row["ENV_A1_RT"]. "</td><td colspan=\"2\">". $row["ENV_A1_LP"]. "</td></tr>";
echo "<tr><td>Feed solenoid</td><td>Feed duration</td><td>Feed trim</td><td>Feed interval</td><td colspan=\"2\">Time to feed</td></tr>";
echo "<tr><td>". $row["ENV_A1_FS"]. "</td><td>". $row["ENV_A1_FD"]. "</td><td>". $row["ENV_A1_FT"]. "</td><td>". $row["ENV_A1_FI"]. "</td><td colspan=\"2\">". $row["ENV_A1_TTF"]. "</td></tr>";
echo "<tr><td>Fan</td><td>Humidity average/minute</td><td colspan=\"2\">Humidity average/hour</td><td colspan=\"2\">Humidity average/day</td></tr>";
echo "<tr><td>". $row["ENV_A1_FAN"]. "</td><td>". $row["ENV_A1_HAM"]. "</td><td colspan=\"2\">". $row["ENV_A1_HAH"]. "</td><td colspan=\"2\">". $row["ENV_A1_HAD"]. "</td></tr>";
$print1 = true;
}
if (!empty($row["VPD_A1_AIR"]) && $print2 === false && $print1 === true) {
echo "<tr><td>Air VPD</td><td>VPD(1)</td><td>VPD(2)</td><td>VPD(3)</td><td colspan=\"2\">VPD(4)</td></tr>";
echo "<tr><td>". $row["VPD_A1_AIR"]. "</td><td>". $row["VPD_A1_L0"]. "</td><td>". $row["VPD_A1_L1"]. "</td><td>". $row["VPD_A1_L2"]. "</td><td colspan=\"2\">". $row["VPD_A1_L3"]. "</td></tr>";
echo "<tr><td>Leaf temp (1)</td><td>Leaf temp (2)</td><td colspan=\"2\">Leaf temp (3)</td><td colspan=\"2\">Leaf Temp (4)</td></tr>";
echo "<tr><td>". $row["VPD_A1_LFT_0"]. "</td><td>". $row["VPD_A1_LFT_1"]. "</td><td colspan=\"2\">". $row["VPD_A1_LFT_2"]. "</td><td colspan=\"2\">". $row["VPD_A1_LFT_3"]. "</td></tr>";
$print2 = true;
}
if ($print1 === true && $print2 === true) {
break;
}
}
} else if ($print1 === false || print2 === false) {
if ($print1 === false) {
echo "<tr><td width=\"17%\">Air Temp</td><td width=\"24%\">Air Temp error</td><td width=\"18%\">RH%</td><td width=\"15%\">RH% error</td><td width=\"13%\">CO2</td><td width=\"13%\">CO2 error</td></tr>";
echo "<tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>";
echo "<tr><td>Lights</td><td>Light intensity</td><td>Return TDS</td><td>Return temp</td><td colspan=\"2\">Pressure </td></tr>";
echo "<tr><td> </td><td> </td><td> </td><td> </td><td colspan=\"2\"> </td></tr>";
echo "<tr><td>Feed solenoid</td><td>Feed duration</td><td>Feed trim</td><td>Feed interval</td><td colspan=\"2\">Time to feed</td></tr>";
echo "<tr><td> </td><td> </td><td> </td><td> </td><td colspan=\"2\"> </td></tr>";
echo "<tr><td>Fan</td><td>Humidity average/minute</td><td colspan=\"2\">Humidity average/hour</td><td colspan=\"2\">Humidity average/day</td></tr>";
echo "<tr><td> </td><td> </td><td colspan=\"2\"> </td><td colspan=\"2\"> </td></tr>";
}
if ($print2 === false) {
echo "<tr><td>Air VPD</td><td>VPD(1)</td><td>VPD(2)</td><td>VPD(3)</td><td colspan=\"2\">VPD(4)</td></tr>";
echo "<tr><td> </td><td> </td><td> </td><td> </td><td colspan=\"2\"> </td></tr>";
echo "<tr><td>Leaf temp (1)</td><td>Leaf temp (2)</td><td colspan=\"2\">Leaf temp (3)</td><td colspan=\"2\">Leaf Temp (4)</td></tr>";
echo "<tr><td> </td><td> </td><td colspan=\"2\"> </td><td colspan=\"2\"> </td></tr>";
}
}
$time_end = microtime(true);
$time = number_format((($time_end - $time_start) * 1000000), 4);
// "<p>loaded in $time microseconds</p>";
?>
I wrote a dos program once was something like
Line10 I dominate
Line 20 Go to Line 10
1985. ?
Was a little more elaborate but 2 lines. Pardon my memory you get the gist.
Next step, separation of concerns write a little CRUD API and populate the view using JavaScript instead, so you're not dumping all the HTML into PHP, which is a special kind of hell to maintain.
Next step, separation of concerns write a little CRUD API and populate the view using JavaScript instead, so you're not dumping all the HTML into PHP, which is a special kind of hell to maintain.
I went and looked up what a CRUD API was, I'm not sure why I need one. I don't want to break out any control to the web interface. I did go and find a php table generator (donquixote/cellbrush) and I wanted to use that and move the styling to CSS. Then it should be easy to make changes to the tables without having to verify a bunch of encapsulated html.
My database inserts are auto-generated by a separate python script, the db records come in over ttl serial as json and I flatten them to one level and use that as column names.