-2
I am a beginner in PHP. My intention is to create a variable that will store snippets of a DIV in HTML. However, some excerpts of this HTML contain PHP instructions, and I don’t know how to make these instructions "readable", so to speak.
My code is just below. Note that I have the variable $variavel
. My problem is inside the paragraph teacher.
Grateful!
<?php
$variavel .= '
<a href="meusite.php?id='.$row["id"].'" target="_blank">
<div class="grid__item large--three-tenths medium--five-tenths">
<img src="imagens/imagem.jpg" alt="'.utf8_encode($row["fullname"]).'" title="'.utf8_encode($row["fullname"]).'">
<p class="h6">'.utf8_encode($row["fullname"]).'</p>
<p class="professor">
/* COMO COLOCAR ESTE TRECHO? */
$iddocurso = $row["id"];
$professor = "SELECT firstname, lastname FROM mdl_course";
$resultProf = $conn->query($professor);
if ($resultProf->num_rows == 1) {
while($row2 = $resultProf->fetch_assoc()) {
echo 'Professor: '.utf8_encode($row2["firstname"]).' '.utf8_encode($row2["lastname"]);
}
} else if ($resultProf->num_rows > 1) {
$array_professores = array();
while ($row2 = $resultProf->fetch_array()){
$array_professores[] = utf8_encode($row2['firstname']).' '.utf8_encode($row2['lastname']);
}
$professores = implode('; ', $array_professores);
echo 'Professores: '.$professores;
} else {
echo "Sem professor cadastrado";
}
/* ATÉ AQUI */
</p>
<span>Acessar</span>
</div>
</a>
';
?>
Important you [Dit] your question and explain objectively and punctually the difficulty found, accompanied by a [mcve] of the problem and attempt to solve. To better enjoy the site, understand and avoid closures and negativities worth reading the Stack Overflow Survival Guide in English.
– Bacco