这是我的代码。
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 已经在数据库中。
记录的.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 连接类)一样)。
一切正常,但是当查看器进入页面时,方法(查询结果)的数据不显示,它们仅在重新加载后显示!我不知道有什么问题。请解决。
谢谢!