2012-01-18 4 views
0

У меня есть некоторые данные в этой таблице mysql, но он ничего не показывает в таблице html.
Но я почти уверен, что код не ошибается.Имея некоторые проблемы с отображением результата запроса

(набл: Я использую «Smarty PHP шаблон», просто чтобы не смешивать HTML с PHP)
Другое наблюдение, я не вставить полный код (pesquisa.tpl).
Представьте себе, что aluno = пользователя и Pesquisa = поиск

-> 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; 
    } 
} 
?> 

-> 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); 

?> 

-> 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} 
+0

Можете ли вы вставить 'var_dump ($ alunos)' перед назначением smarty? – DerVO

+0

Извините, я не включил php-файл на мою страницу handler.php ... Это была ошибка. –

+0

@RamonSaraiva - после того, как цикл 'foreach' попытается отобразить содержимое' $ alunos', используя 'print_r ($ alunos);', он пуст? – Cyclonecode

ответ

1

В вашем классе вы должны вернуть $ this-> telefone;

.: например

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

Edit: вы изменили его? он сказал это ранее:

public function getTelefone() { 
    return $telefone; 
} 
Смежные вопросы