I'm just a weekend programmer so forgive my ignorance.
I have a "Status Board" webpage which shows the operational status of our command centre. It's built very basically with html tables/css/js/php.
I've used inline php to display the information retrieved from the database in the table boxes. The information is displayed inside a link to a modal so then this box can be clicked on and updated.
I've used PDO to initiate the DB connection. See DB snippet
<?php
try{
$db = new pdo("mysql:host=localhost;dbname=dbname;charset=utf8","dbusername","dbpassword");
} catch(PDOException $e) {
die("Connection Error: " . $e->get);
}
?>
At the top of the html webpage, I retrieve ALL of the information from the database regarding these textboxes and join them all, as an array, to an empty array. See snippet. Also see attached png for how db is laid out.
<?php
//Wording Query
$wordingquery = "SELECT * FROM text_box";
$wordingresult = $db->query($wordingquery);
$table_wording = [];
foreach($wordingresult as $text){
array_push($table_wording,[$text["id"],$text["wording"],$text["title"],$text["color"],$text["type"],$text["min"],$text["max"]]);
};
?>
When I want to display the relevant information in one of the text boxes, I iterate through this array and find it by the "id" and update the box "wording". See Snippet
<td class="condition_<?=$mode;?>" colspan="12">LONG TERM INFORMATION</td>
</tr>
<tr>
<!-- Information Rows 1 -->
<?php
foreach($table_wording as $words){
if($words[0] === "lin2"){
?>
<td style="border-right-width: 3px; border-right-style: solid" colspan="6" id="<?=$words[0];?>" class='<?=$words[3];?>'>
<a data-toggle="modal" data-target="#<?=$words[0];?>Modal" >
<?=$words[1];?>
</a>
</td>
<?php };
};
?>
Is this the most efficient way to display this data from the database? Is it possible to display the information directly without having to attach it to an array and iterate through the array. Obviously bearing in mind if I have 100> of these boxes then if it's done directly then there could be too many queries to the db?