我有一个问题。如何在此函数ListarGeral()中挽救变量$ row。所以我可以使用函数EditarGeral()。我试过,但没有发生任何事情
这是我尝试做的事情:
<?php
include ('Banco.php');
Class GeralControle {
private $consulta;
private $row = array();
public function GeraloDao() {
$novaconexao = new Banco();
$this->consulta = $novaconexao->conectar();
}
public function ListarGeral() {
$this->GeraloDao();
echo '<table border="1" cellspacing="2">
<tr>
<td>ID</td>
<td>CPF</td>
</tr>';
if ($resultado = $this->consulta->query("select * from cadastro")) {
while ($this->row = $resultado->fetch_row()) {
echo '<tr>
<td>'.$this->row[0].'</td>
<td>'.$this->row[1].'</td>
</tr>';
echo $this->row[0];
}
$resultado->close();
}
echo '</table>';
}
public function EditarGeral(){
$this->ListarGeral();
echo $this->row[0];
}
}
$pessoa2 = new GeralControle();
$pessoa2->ListarGeral();
$pessoa3 = new GeralControle();
$pessoa3->EditarGeral();
谢谢!
答案 0 :(得分:0)
if ($resultado = $this->consulta->query("select * from cadastro")) {
$rows = array();
while ($this->row = $resultado->fetch_row()) {
echo '<tr>
<td>'.$this->row[0].'</td>
<td>'.$this->row[1].'</td>
</tr>
';echo $this->row[0];
array_push($rows, $this->row);
}
EditarGeral($rows);
}