I am struggling with what seems to be a simple task. I have two tables in my database:
Table devices:
id, uid, devicecode, devicename, devicetype
Table devicelogs:
id, devicecode, timelogged, devicestatus
Before my page loads, I get all the user's devices with the following query:
$sql = "SELECT * FROM devices WHERE `uid`='1'";
This gets me all the user's devices which I then use to create 'switches' on the page using checkboxes.
To set the checkbox's status, I need to then check what the last devicestatus of that device was in the 'devicelogs' table (on or off).
I am guessing I would have to do a join of some sort where the devicelogs table should show the last records of each of the devices.