I'm very new to PHP, so please excuse me if this is a silly question.
I have a separate PHP file which contains a few functions, they were originally in the same document as the HTML site, but I wanted to move them to their own PHP file.
Originally in the HTML I had PHP connect to an SQL server and then ran an SQL Query, then I wanted the results of that query to populate a drop down box, so each row in the returned query was an , this worked great but when I move all that functionality to the separate PHP file it's no longer working.
I have one function now, which connects to the database, runs the query and then attempts to write the output, but I think it's this section that's causing the problem.
I have included this new PHP function file.
Here's the function:
function results() {
$connection = db();
$smt = $connection->prepare('SELECT * FROM tblResults');
$smt->execute();
$data = $smt->fetchAll();
foreach ($data as $row) {
echo "<option>".$row['Score']."</option>";
}
}
And in the HTML I have this code to call the function:
<select class="selectpicker" data-live-search="true" data-width="auto">
<?php results(); ?>
</select>
As I said, I'm new to PHP so I'm sorry if this is an obvious error or if the format is wrong.
Any help would be greatly appreciated.