I have a PHP document which contains mostly html, but also some MySql queries which look like this:
<?php
require_once('connectdata.php');
$db = mysqli_connect(DB_HOST, DB_BENUTZER, DB_PASSWORT, DB_NAME);
$myquery = "SELECT name FROM Entries WHERE typ = 'Communication' ORDER BY name";
$result = mysqli_query($db, $myquery);
while($row = mysqli_fetch_object($result))
{
echo "$row->name";
}
mysqli_close($db);
I am using this exact code several times in my document to echo the data I want to display. Is this a good practice or is there a way to just connect once get all the data and echo them later in the document?
Is it bad if I leave it like that?