У меня есть некоторые данные в этой таблице 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}
Можете ли вы вставить 'var_dump ($ alunos)' перед назначением smarty? – DerVO
Извините, я не включил php-файл на мою страницу handler.php ... Это была ошибка. –
@RamonSaraiva - после того, как цикл 'foreach' попытается отобразить содержимое' $ alunos', используя 'print_r ($ alunos);', он пуст? – Cyclonecode