I have a problem that I can not figure out, I can not understand why the ID of the DIV does not get the value coming from php, using the value of the constant $i
, it always receives the last value of the loop.
the proposal is to show / hide the DIV selected by ID when clicked on the Name href.
<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>
Second 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>