There is a confusion in your mind about how HTML and PHP interact. The way to do this is to use the statement echo
from inside the PHP part of your code.
Edit: Try this new version. The code is cleaner:
<?php
$previousrow = array ('layout' => '');
if (mysqli_num_rows($result3) > 0) {
while($row = mysqli_fetch_assoc($result3)) {
if($row['layout'] != $previousrow['layout']) { // new group
if ($previousrow['layout'] !=== '') { // not on first row
print_footers ($previousrow);
}
print_headers ($row);
}
print_group_items ($row);
$previousrow = $row;
}
print_footers ($previousrow);
}
function print_group_items ($this_row) {
echo " <!-- Print group items -->"
; // will depend on $this_row
}
function print_headers ($this_row) {
echo "<!-- Print headers -->
"; // will depend on $this_row
}
function print_footers ($this_row) {
echo "<!-- Print footers -->
"; // will depend on $this_row
}
?>
This was the previous version and wasn't correct, due to a.o. a tipo in the line containing print_footers;
without ()
.
<?php
$seriesgroup = '';
$firstgroup = 1;
if (mysqli_num_rows($result3) > 0) {
while($row = mysqli_fetch_assoc($result3)) {
if($row['layout'] != $seriesgroup) {
if (! $firstgroup) {
print_footers ();
$firstgroup = 0;
}
print_headers ();
$seriesgroup = $row['layout'];
}
print_group_items ($row);
}
print_footers;
}
function print_group_items ($this_row) {
echo " <!-- Print group items -->"
; // will depend on $this_row
}
function print_headers () {
echo "<!-- Print headers -->
";
}
function print_footers () {
echo "<!-- Print footers -->
";
}
?>