所以,现在我有一个 PHP 函数,它利用 PDO 返回特定表的第一行.这工作正常,但我想返回所有信息,同时能够组织所有信息.
So, right now I have a PHP function that utilizes PDO to return the first row of a specific table. That works fine, but I want to return all of the information, while being able to organize it all.
我有表 zip__admins,我正在尝试从表中返回 first_name 和 last_name.有了这些信息,我在登录页面上有一个按钮,要求用户选择他们的姓名(每个人都有自己的按钮)进行登录.截至目前,我将返回一个结果,而不是两个结果.如何修改以下代码以返回两个结果,并将数据输入到模板参数中.
I have the table zip__admins and I'm trying to return the first_name and last_name from the table. With this information, I have a button on the login page asking the user to select their name (each person gets their own button) to sign in. As of now, I'm returning one result, instead of two results. How can I modify the below code to return two results, and input the data into a templating parameter.
final public function fetchAdminInfo() {
global $zip, $db, $tpl;
$query = $db->prepare('SELECT first_name, last_name FROM zip__admins');
$query->execute();
$result = $query->fetch(PDO::FETCH_ASSOC);
$tpl->define('admin: first_name', $result['first_name']);
$tpl->define('admin: last_name', $result['last_name']);
}
这是我的桌子:![SQL 表][1]
Here is my table: ![SQL Table][1]
需要使用fetchAll()
$result = $query -> fetchAll();
foreach( $result as $row ) {
echo $row['first_name'];
echo $row['last_name'];
}
这篇关于PDO 返回所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
MySQLi准备好的语句&foreach 循环MySQLi prepared statement amp; foreach loop(MySQLi准备好的语句amp;foreach 循环)
mysqli_insert_id() 是从整个服务器还是从同一用户获Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是从整个服务器还是从同一用户获取记录?)
PHP MySQLi 无法识别登录信息PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 无法识别登录信息)
mysqli_select_db() 需要 2 个参数mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 个参数)
Php mysql pdo 查询:用查询结果填充变量Php mysql pdo query: fill up variable with query result(Php mysql pdo 查询:用查询结果填充变量)
MySQLI 28000/1045 用户“root"@“localhost"的访问MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用户“root@“localhost的访问被拒绝)