2
I’m having a problem that I can’t figure out, I can’t understand why the ID of the DIV does not receive the value from php, using the value of the constant $i
, He always gets the last value of the loop.
the proposal is to show/hide the DIV selected by ID when clicked on href of Name.
<div class="panel-body">
<?php
//classe
class Clientes{
public $id;
public $nome;
public $cpf;
public $endereco;
public function __construct($id,$nome,$cpf,$endereco){
$this->id = $id;
$this->nome = $nome;
$this->cpf = $cpf;
$this->endereco = $endereco;
}
};
$cliente1 = new Clientes("0","Bruno","550","rua protasio");
$cliente2 = new Clientes("1","Thiago","4400", "rua barao");
$cliente3 = new Clientes("2","Ana","650","rua nova");
$cliente4 = new Clientes("3","Beatriz","840","rua velha");
$cliente5 = new Clientes("4","Gustavo","960","rua brasil");
$cliente6 = new Clientes("5","Alberto","123255","rua jovem");
$cliente7 = new Clientes("6","Jose","466897","rua normal");
$cliente8 = new Clientes("7","Andre","44699", "rua das petalas");
$cliente9 = new Clientes("8","Vinicius","87750", "rua irmao");
$cliente10 = new Clientes("9","Bruna","4890", "rua bolao magico");
$arrayclientes = array($cliente1, $cliente2,$cliente3,$cliente4,$cliente5,$cliente6,$cliente7,
$cliente8,$cliente9,$cliente10);
for($i=0;$i<10;$i++){
$arrayclientes[$i]->id;
$arrayclientes[$i]->nome;
$arrayclientes[$i]->cpf;
$arrayclientes[$i]->endereco;
include("thumbimg.php");
}
?>
</div>
According to Code:
<script>
function display()
{
var elem = document.getElementById("disp2");
alert(elem);
if(elem.style.visibility == "hidden"){
elem.style.visibility="";
} else {
elem.style.visibility="hidden";
}
}
</script>
<?php
echo "disp" .$arrayclientes[$i]->id;
?>
<div>
<h4><a onclick="display()"> Nome:<?php echo $arrayclientes[$i]->nome; ?></h4></a>
<div id=" <?php echo "disp" .$arrayclientes[$i]->id; ?> ">
<h5>Cpf:<?php echo $arrayclientes[$i]->cpf; ?></h5>
<p>Endereco: <?php echo $arrayclientes[$i]->endereco; ?></p>
</div>
</div>
look if this answer can help you. http://answall.com/questions/22726/como-esconder-mostraruma-div-em-html
– Marconi
the problem I realized is with the <div id=""> that does not receive the value, the javascript works normally
– Thiago Freitas
The second code is what goes in the include?
– Guilherme Nascimento
yes, that’s right
– Thiago Freitas
So see if the answer helps.
– Guilherme Nascimento