How to organize quotation marks of HTML and PHP content inside echo?

Asked

Viewed 463 times

0

Dear Colleagues, I am faced with 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 IF echo:

<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 wish that only if the id exists will the word lynched appear.

Someone could give me a boost?

Thanks in advance!

3 answers

0


If I understood correctly, that would be it?

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";
}

0

Always when you put HTML within a echo, Remember to organize the quotes! If you open an echo with double quotes " the attributes of HTML should be opened with single quotation marks ', and so on.

Your code would look 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";

}

0

Thank you very much for the answers dear Daniel and Sampaio Leal, helped me a lot, really was making some confusions with regard to the quotation marks, but also in the concatenating part, transforming this:

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

for that reason:

. $row_usuario['id_relacionado'] .

This was the structure that 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 echo with signal = I was returning the following error:

Parse error: syntax error, Unexpected '='

I did the removal and everything worked again, even though the problem was already solved someone could explain me this difference of using echo with or without equal sign?

Thank you so much again!

  • Good that it worked. I’ve never seen echo with =, it’s a sign of type assignment on "$var = x". echo is followed straight by what will be "echoed" in quotes. Don’t forget to accept the answer to help other users. Good luck there.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.