Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Wiele obiektów i jedna zmienna.
EdeusEx
post 6.04.2008, 11:03:52
Post #1





Grupa: Zarejestrowani
Postów: 49
Pomógł: 1
Dołączył: 6.04.2008

Ostrzeżenie: (20%)
X----


mam problem, ale pierw przedstawie skrypty:

game.php
  1. <?php
  2. require_once('mysql.php');
  3. require_once('player.php');
  4. require_once('website.php');
  5. class Game {
  6. function Game($getPlayerName) {
  7. $this->PlayerName = $getPlayerName;
  8. $this->SQL = new MySQL($this->PlayerName);
  9. $this->Player = new Player($this->PlayerName);
  10. $this->Website = new Website($this->PlayerName);
  11. }
  12. }
  13. ?>


Najważniejszy jest player.php:
  1. <?php
  2. class Stats extends MySQL {
  3. function getPercent($stat, $precision=0) {
  4. $getStat = mysql_query(&#092;"SELECT * FROM \".$this->prefix(0, \"player_stats\").\" WHERE user='\".$this->PlayerName.\"'\");
  5. $_Stat = mysql_fetch_assoc($getStat);
  6. @$countPC = round(($_Stat[$stat]/$_Stat[$stat.'_max'])*100, $precision);
  7.  
  8. return $countPC;
  9. }
  10.  
  11. function getValue($stat) {
  12. $getStat = mysql_query(&#092;"SELECT * FROM \".$this->prefix(0, \"player_stats\").\" WHERE user='\".$this->PlayerName.\"'\");
  13. $_Stat = mysql_fetch_assoc($getStat);
  14. return $_Stat[$stat];
  15. }
  16.  
  17. function changeValue($stat) {
  18.  
  19. }
  20. }
  21.  
  22.  
  23. class Player extends MySQL {
  24. function Player() {
  25. $this->EQ = new Equipment($this->PlayerName);
  26. $this->Stats = new Stats($this->PlayerName);
  27. $this->Account = new Account($this->PlayerName);
  28. $this->Messages = new Messages($this->PlayerName);
  29. $this->Guild = new Guild($this->PlayerName);
  30. }
  31. }
  32. ?>


mysql.php
  1. <?php
  2. class MySQL {
  3. public $PlayerName = &#092;"\";
  4.  
  5.  
  6. function __construct($getPlayerName) {
  7. if ($this->isConnected==false) {
  8. if (@!mysql_connect($this->db_host, $this->db_user, $this->db_pass)) {
  9. die(&#092;"0\");
  10. } else {
  11. $this->isConnected = true;
  12. }
  13. }
  14. $this->PlayerName = $getPlayerName;
  15. }
  16. }
  17. ?>



I index.php, gdzie jest deklaracja:
  1. <?php
  2. require_once('includes/game.php');
  3.  
  4. if (!isset($_SESSION['member'])) {
  5. $setPlayerName = 'guest';
  6. } else {
  7. $setPlayerName = $_SESSION['member'];
  8. }
  9.  
  10. $Game = new Game($setPlayerName);
  11. ?>

Dlaczego, wywołując $Game->Player->Stats->getValue('blabla'); $this->PlayerName nie ma żadnej wartości? Gdzieś zgubiłem przekazywanie ^.-

Ten post edytował EdeusEx 6.04.2008, 11:08:47
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.07.2025 - 10:28