仅获取数据库中的第一行值

时间:2016-12-08 07:29:26

标签: php database pdo

我们正试图从数据库中获取价值显示所有行的相关值。

但是代码只在DB&中获取第一行值显示所有行的相同值。

数据库

enter image description here

网站

enter image description here

compile 'com.squareup.retrofit2:retrofit:2.0.0'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
compile 'com.squareup.retrofit2:converter-scalars:2.0.1'

完整代码:http://pastebin.com/GnT980nL

1 个答案:

答案 0 :(得分:0)

您需要使用fetchAll()代替fetch()

http://php.net/manual/ru/pdostatement.fetchall.php

您的功能必须如下:

function getDesignerCollection() {
    global $is_admin;
    $user_home = new USER();
    require_once '../../app/Mage.php';

    Mage::app();

    $stmts = $user_home->runQuery("SELECT * FROM tbl_users WHERE userID=:uid");
    $stmts->execute(array(
        ":uid" => $_SESSION['userSession']
    ));
    $rows = $stmts->fetchAll(PDO::FETCH_ASSOC);
}

现在在$rows中你有一组关联数组。

相关问题