页面重新加载后显示查询结果数据

时间:2013-08-23 19:35:37

标签: php class oop object

这是我的代码。

index.php文件:

$viewer_id = $_SESSION['viewer_id'];
    $db = new Database('144.76.6.45','5432','3331','asd','31sd23');
    $db->querySelect("SELECT * FROM users WHERE vk_id = $viewer_id");
    $row = $db->STH->fetch();
    if(empty($row)){
        require 'template/default/not_logged.php';
    }
    else {
        require 'template/default/logged.php';
    }

这部分是可以理解的。连接数据库,进行查询。如果查看者的id在db-logged.php中,如果不是 - not_logged.php

让我们说观众ID已经在db。

logged.php文件:

<div id="text-right">
                            <p>Игровой ник: <?php $user->getEuName(); ?></p>
                            <p>Cоциум: <?php $user->getSociety(); ?></p>
                            <p>Основная профессия: <?php $user->getMainProfession(); ?></p>
                            <p>Дополнительная информация: <?php $user->getNotes(); ?></p>
                            <p>Ищу команду для совместной охоты: <?php $user->getWantTeam(); ?></p>
                        <div class="edit-info"><a href="#">Редактировать</a></div>
                        </div>

此方法从db获取信息。

class User extends Database {
    public $vk_id;
    public $eu_name;
    public $eu_society;
    public $eu_notes;
    public $eu_want_team;
    public $eu_data;

    function __construct() {
    parent::__construct('144.76.6.45','5432','eu','eu','eu123');
    }

    function getEuName() {
        $this->querySelect("SELECT eu_name FROM users WHERE vk_id = $this->viewer_id");
        $row = $this->STH->fetch();
        print '<b>'.$row['eu_name'].'</b>';
    }

    function getSociety() {
        $this->querySelect("SELECT eu_society FROM users WHERE vk_id = $this->viewer_id");
        $row = $this->STH->fetch();
        print '<b>'.$row['eu_society'].'</b>';
    }

    function getNotes() {
        $this->querySelect("SELECT eu_notes FROM users WHERE vk_id = $this->viewer_id");
        $row = $this->STH->fetch();
        print '<b>'.$row['eu_notes'].'</b>';
    }

    function getWantTeam() {
        $this->querySelect("SELECT eu_want_team FROM users WHERE vk_id = $this->viewer_id");
        $row = $this->STH->fetch();
        if($row['eu_want_team'] == 'TRUE') {
            print '<b>Да</b>';
        }
        else {
            print '<b>Нет</b>';
        }
    }

    function getMainProfession() {
        $this->querySelect("SELECT eu_main_profession FROM users WHERE vk_id = $this->viewer_id");
        $row = $this->STH->fetch();
        print '<b>'.$row['eu_main_profession'].'</b>';
    }

}
$user = new User();

这是带get方法的用户类。(他包含在index.php中,如database.php(db connection class))。

一切都还可以,但是当观众来到页面时,方法数据(查询结果)没有显示,它们只显示 AFTER RELOAD!我不知道问题是什么。请解决。

谢谢!

0 个答案:

没有答案