0
I’m building a book registration system, it’s quite easy actually, it only involves a little bit of PHP and Mysql, but my problem is time to display. See, it’s a lot of information, so I wanted to make a button that would hide the div of the book selected with this method:
<script language="javascript" type="text/javascript">
function Mudarestado(el) {
var display = document.getElementById(el).style.display;
if(display == "none")
document.getElementById(el).style.display = 'block';
else
document.getElementById(el).style.display = 'none';
}
</script>
So far so good, he was hiding the div, but I started adding more and more books, and each one has its own hide button, and here’s the problem: The first button hides itself, and the other’s buttons also hide the first, look at the code:
$div = "div_{$linha['id']}";
// aqui eu mostro os valores de minha consulta
echo "Identificador: {$linha['id']} <br />";
echo '<div id=".$div.">';
echo "Nome: {$linha['nome']} <br />";
echo "Autor: {$linha['autor']} <br />";
echo "Editora: {$linha['editora']} <br />";
echo "Gênero: {$linha['genero']} <br />";
echo "Volume: {$linha['volume']} <br />";
echo "Ano: {$linha['ano']} <br />";
echo "Número de Páginas: {$linha['numero_de_paginas']} <br />";
echo "Outros Dados: {$linha['outros_dados']} <br />";
echo "</div>";
echo '<button type="button" onclick="Mudarestado(\'.$div.\')">Mostrar/Esconder</button><br /><br />';
I have tried to change the $div variable, add it, print it on the screen to identify some error, it seems really impossible! I ask the community to help me solve this problem, and also apologise if I did something wrong in this post, it’s my first time in a forum.
Try it like this
echo "Identificador: ".$linha['id']." <br />";
and it depends on your php parameter this declaration used, If you are trying to put php variable for javascript, it does not work well. Are different language.– KingRider
It did not work ;-;. Even so, very sheltered for proposing a solution.
– Zenas
What are you using it for
{ }
? if it is tried for Angularjs?– KingRider
Well, I figured that as the result of the query would display multiple results, one div was required for each book.
– Zenas
Right, if you are using correct Mysql, you need to use repetition to result from vector. Use
mysql_fetch_array
and follow the example http://php.net/manual/en/function.mysql-fetch-array.php– KingRider
I am using: fetch(PDO::FETCH_ASSOC).
– Zenas
I understood and sorry or use Pdo, if this using PDO is different from php, put tags there
PDO
.– KingRider
All right buddy! I appreciate your help and I’m sorry if I wasn’t specific in the tags.
– Zenas