我可以回复$row_count
,但我无法打印$first
。
帐户表包含fname
和lname
。
任何人都可以解决这个问题吗?
public function getAccountInfoAll(){
$acc_info = $this->con->query("SELECT * FROM account");
$results = $acc_info->fetchAll();
$row_count = $acc_info->rowCount();
echo $row_count.' rows selected';
while ($row = $acc_info->fetchAll())
{
$first = $row['fname'];
echo $first;
}
}
答案 0 :(得分:0)
猜测你使用PDO,所以这就是你做错了什么:
$acc_info = $this->con->query("SELECT * FROM account");
$acc_info->execute();
$results = $acc_info->fetchAll(PDO::FETCH_ASSOC);
$row_count = $acc_info->rowCount();
echo $row_count.' rows selected';
foreach($results AS $row) {
$first = $row['fname'];
echo $first.'<br />';
}
答案 1 :(得分:0)
这样的事情:
public function getAccountInfoAll(){
$acc_info = $this->con->prepare("SELECT * FROM account");
$acc_info->execute();
$row_count = $acc_info->rowCount();
echo $row_count.' rows selected';
while ($row = $acc_info->fetch(PDO::FETCH_ASSOC)) {
$first = $row['fname'];
echo $first;
}
}