显示查询结果时遇到一些问题

时间:2012-01-18 13:41:14

标签: php mysql html pdo

我在这个mysql表中有一些数据,但它没有在html表中显示任何内容 但我几乎可以肯定代码没错。

(Obs:我正在使用“Smarty PHP模板”,只是为了不将HTML与PHP混合)
另一个观察,我没有粘贴(pesquisa.tpl)的完整代码 想象一下aluno = user和pesquisa = search

- > pesquisa_aluno.class.php

<?php

class PesquisaAluno {
    private $nome;
    private $sobrenome;
    private $rg;
    private $email;
    private $telefone;

    public function __construct($nome, $sobrenome, $rg, $email, $telefone) {
        $this->nome = $nome;
        $this->sobrenome = $sobrenome;
        $this->rg = $rg;
        $this->email = $email;
        $this->telefone = $telefone;
    }

    public function getNome() {
        return $this->nome;
    }

    public function getSobrenome() {
        return $this->sobrenome;
    }

    public function getRg() {
        return $this->rg;
    }

    public function getEmail() {
        return $this->email;
    }

    public function getTelefone() {
        return $this->telefone;
    }
}
?>

- &GT; pesquisa.php

<?php

include("classes/pesquisa_aluno.class.php");

$alunos = array();
foreach ($connection->query("SELECT * FROM alunos") as $row) {
    $aluno = new PesquisaAluno($row["nome"], $row["sobrenome"], $row["rg"], $row["email"], $row["telefone"]);
    $alunos[] = $aluno;
}

$smarty->assign('alunos', $alunos);

?>

- &GT; pesquisa.tpl

{foreach from=$alunos item=aluno}
   <tr>
       <td>{$aluno->getNome()}</td>
       <td>{$aluno->getSobrenome()}</td>
       <td>{$aluno->getRg()}</td>
       <td>{$aluno->getEmail()}</td>
       <td>{$aluno->getTelefone()}</td>
   </tr>
{/foreach}

1 个答案:

答案 0 :(得分:1)

在课堂上你应该返回$ this-&gt; telefone;

e.g:

public function getTelefone() {
    return $this->telefone;
}

编辑:你改变了吗?它之前说过:

public function getTelefone() {
    return $telefone;
}