PDO在其他功能中使用时不返回结果

时间:2013-08-26 22:02:28

标签: php sql pdo

当我刚刚执行$backend->fetchAdminInfo();时,PDO工作正常,但当我在单独的函数中执行$backend->fetchAdminInfo();时,没有返回任何结果。出于某种原因,当它返回first_namelast_nameavatar时,它返回null。

以下是代码。

public $adminCount;

final public function fetchAdminInfo() {
    global $zip, $db, $tpl;

    $query = $db->prepare('SELECT first_name, last_name, avatar FROM zip__admins ORDER BY first_name ASC');
    $query->execute();

    $result = $query->fetchAll();

    $id = 1;
    foreach($result as $row) {
        $tpl->define('admin: first_name-' . $id, $row['first_name']);
        $tpl->define('admin: last_name-' . $id, $row['last_name']);
        $tpl->define('admin: avatar-' . $id, $row['avatar']);
        $id++;
    }
    $this->adminCount = $id;
}

final public function addSnippet($z) {
    global $tpl;

    if(isset($z) && !empty($z)) {
        switch($z) {
            case 'login: show-admins':
                $this->fetchAdminInfo();
                $admins = ' ';

                for($id = 1; $this->adminCount > $id; $id++) {
                  $admins .= '<li data-name="{admin: first_name-'. $id .'} {admin: last_name-'. $id .'}" onclick="submitValue('. $id .')">';
                  $admins .= '<div class="av-overlay"></div><img src="{site: backend}/img/avatars/{admin: avatar-'. $id .'}.jpg" class="av">';
                  $admins .= '<span class="av-tooltip">{admin: first_name-'. $id .'} {admin: last_name-'. $id .'}</span>';
                  $admins .= '</li>';
                }

                $tpl->Define('snippet: show-admins', $admins);
                $tpl->display();
            break;
        }
    } else {
        die("HELLO!");
    }
}

0 个答案:

没有答案