How to organize HTML and PHP content quotes within echo? [duplicate]

0

Dear Colleagues, I'm facing a certain difficulty in including a certain content within an echo, for example:

I have this conditional structure:

if ($row_usuario['id_relacionado'] != 0) {


    echo = " ";


}else{

echo = "Não existe arquivo relacionado";

}

I need to insert the following DIV into the echo of the IF:

<div id="id_resultado"><a href="visualizar.php?id=<?php echo $row_usuario['id_relacionado']?>"><?php echo $idrelacionado['numero']?></a></div>

For the following reason, I would like that only if the id exists the link will appear.

Could someone give me strength?

Thank you in advance!

    
asked by anonymous 16.10.2016 / 20:11

3 answers

0

If I understood correctly, would that be?

if ($row_usuario['id_relacionado'] != 0) {
 echo "
    <div id='id_resultado'><a href='visualizar.php?id=". $row_usuario['id_relacionado'] ."'>". $idrelacionado['numero'] ."</a></div>";
} else{
echo "Não existe arquivo relacionado";
}
    
16.10.2016 / 20:27
0

Whenever you put HTML inside a echo , remember to arrange the quotation marks! If you open an echo with double quotation marks " the attributes of HTML must be opened with single quotation marks ' , and so on.

Your code looks like this:

if ($row_usuario['id_relacionado'] != 0) {


    echo = "<div id='id_resultado'><a href='visualizar.php?id=" .$row_usuario['id_relacionado'] .">" . $idrelacionado['numero'] ."</a></div>";


}else{

echo = "Não existe arquivo relacionado";

}
    
16.10.2016 / 20:37
0

Thank you very much for the answers dear Daniel and Sampaio Leal, it helped me a lot, I was really making some confusions regarding the quotes, but also in the concatenating part, transforming this:

<?php echo $row_usuario['id_relacionado']?>

for this:

. $row_usuario['id_relacionado'] .

This was the framework I applied and worked:

if ($row_usuario['id_relacionado'] != 0) {


    echo "<div id='id_resultado'><a href='visualizar.php?id=". $row_usuario['id_relacionado'] ."'>". $idrelacionado['numero'] ."</a></div>";


}else{

    echo "Não existe arquivo relacionado.";

}

When I inserted the echo with a = sign it was returning the following error:

Parse error: syntax error, unexpected '='

I did the removal and it all worked again, even if the problem was solved, could anyone explain the difference between using echo with and without an equal sign?

Thank you very much again!

    
16.10.2016 / 21:23