[Solved] Mixing PHP and HTML code [closed]


I am assuming you want the html code here block to only display if the first if test is TRUE. If that is the case, move the trailing } before the html block to after.

<?php           
  foreach ($myResults as $rowNumber => $myResult) {
    if ($rowNumber<$numberOfResults/2) {
      print "<h2>";
      print render($myResult->field_field_item_category[0]['rendered']['#title']) ;       
      print "</h2>";
?>
  html code here
<?php 
     }elseif ($rowNumber>$numberOfResults/2) {   
       print "<h2>";
       print render($myResult->field_field_item_category[0]['rendered']['#title']) ;      
       print "</h2>";
     }
  } 
?>

if you want the html code here to go after both move it out of the middle of the if statement.

<?php           
  foreach ($myResults as $rowNumber => $myResult) {
    if ($rowNumber<$numberOfResults/2) {
      print "<h2>";
      print render($myResult->field_field_item_category[0]['rendered']['#title']) ;       
      print "</h2>";
    }elseif ($rowNumber>$numberOfResults/2) {   
      print "<h2>";
      print render($myResult->field_field_item_category[0]['rendered']['#title']) ;      
      print "</h2>";
    }
  } 
?>
  html code here

Also, indent. It makes the source of errors like this more obvious.

3

solved Mixing PHP and HTML code [closed]