I have an AJAX call to a PHP file where I get the data from MySQL database in a while loop. Then I am returning this back as response. So far so good.
Part of working sample PHP file called by AJAX looks like this. EDIT: echo in this sample is not a part of the some-HTML-included-file.php file in the second example.
... mysql commands ...
while($data = $result->fetch_assoc()){
echo 'some HTML here' . $data['id'];
}
Now because the HTML (here in while loop) is quite big in my application and I use it also in another files, I have it in separate file and just including it.
So the result looks like this
while($data = $result->fetch_assoc()){
echo include 'inc/some-HTML-included-file.php';
}
It kind of works, but it also returns true for successful include which becomes 1 in resulting HTML.
My question is, how to do this the correct way, so I get the result without additional 1s.
Note: I found similar question here, but this obviously does not work in a loop.