gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 14:36:34 25 4
gpt4 key购买 nike

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

(观察:我正在使用“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;
}
}
?>

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

最佳答案

在你的类(class)中,你应该返回 $this->telefone;

例如:

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

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

public function getTelefone() {
return $telefone;
}

关于php - 显示查询结果时遇到一些问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8911092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com