We have a function like this:
function getthis($x){
$dbc = getDBCon();
if ($dbc) {
$sql = "SELECT * FROM `names`";
$res = mysqli_query($dbc, $sql);
while($data = mysqli_fetch_array($res)){
SOME PROCESS...
echo $results;
}
closeDBCon($dbc)
}
and in page:
<?php
$get = getthis($x)
echo '<td>'.$get.'</td>';
?>
But it doesn’t echo results inside <tr> tags and they appear on top of page. It is probably echoing instead of return, but what is causing this problem?
As you say yourself,
echoinstead ofreturnis the problem.echojust prints to the screen exactly when the method is encountered. A possible solution can be to accumlate your results in a variable$outputthroughout the while loop. Once you’re done, you return the contents of$output.