Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Undefined index
Forum PHP.pl > Forum > Przedszkole
banki
Witam,

mam problem z którym ciężko mi idzie.

Mianowicie mam zainstalowanego typera na stronie, i w statystykach jest rubryka na wyświetlenie statystyk użytkownika, jeśli się wpiszę nick użytkownika, który jest w bazie to wyświetlą się jego statystyki, jeśli zaś użytkownika o podanym nicku nie ma, wyświetla się taki wierszyk:

Notice: Undefined index: score in E:\WebServ\httpd\typer\templates_c\%%EF^EF3^EF337948%%stats_user.ihtml.php on line 42

Notice: Undefined index: types in E:\WebServ\httpd\typer\templates_c\%%EF^EF3^EF337948%%stats_user.ihtml.php on line 45


42 linijka
  1. <div class="styper_rightfield"><?php echo $this->_tpl_vars['score']; ?></div>


45 linijka
  1. <?php if ($this->_tpl_vars['roundId'] || sizeof($this->_tpl_vars['types']) > 0): ?>



co można na to poradzić? jeśli ktoś wie co z tym można zrobić proszę o jakąkolwiek pomoc. pozdrawiam
nospor
Najpierw nalezy sprawdzic czy dany index istnieje (isset(), empty()) a dopiero potem jak jest to wyswietlac
mortus
Wypadałoby nick użytkownika pobierać z bazy i podpiąć pod odpowiedni link. Jeżeli już koniecznie chcesz wpisywać nick użytkownika, to przed pobraniem statystyk należy sprawdzić, czy dany użytkownik w bazie istnieje. Jeżeli użytkownik istnieje, to pobieramy jego statystyki, a jeżeli nie istnieje, to wyświetlamy odpowiedni komunikat.
banki
Pewnie trzeba coś zmienić w tym pliku, ale też mi nie idzie, próbowałem zmienić od linijki 28 do 37 kod, kombinować i nic to nie daje


  1. <?php
  2.  
  3.  
  4. class Stats_User extends TyperPage {
  5.  
  6.  
  7. function Stats_User() {
  8.  
  9. parent::TyperPage();
  10. //Typer_Auth::redirectGuest();
  11.  
  12. $this->status = '';
  13. $this->content = '';
  14.  
  15. $this->q = new Queries;
  16.  
  17. $this->db = new DB;
  18. $this->t=new Typer_Smarty(ROOT."layout/stats_user/");
  19. }
  20.  
  21. function getContent() {
  22.  
  23. return $this->getFormular();
  24. }
  25.  
  26. function checkUser($user) {
  27.  
  28. $sql = "SELECT * FROM styper_user WHERE userlogin = '{$user}'";
  29. $res = $this->db->table ($sql);
  30.  
  31. if (count ($res) > 0) {
  32. $this->User = $res[0];
  33. return true;
  34. }
  35. else {
  36. $this->status = textSys('stats:TAKI_UZYTKOWNIK_NIE_ISTNIEJE');
  37. return false;
  38. }
  39. }
  40.  
  41. function checkRound() {
  42.  
  43. if (!$this->roundId) {
  44. $sql = "SELECT roundid FROM styper_round WHERE roundactive = 1";
  45. $roundId = $this->db->table($sql);
  46. $roundId = $roundId[0][0];
  47.  
  48. if (! $roundId) {
  49. $sql = "SELECT max(roundid) FROM styper_round";
  50. $roundId = $this->db->table($sql);
  51. $roundId = $roundId[0][0];
  52. }
  53. }
  54. return $roundId;
  55. }
  56.  
  57. function getFormular() {
  58. $this->roundId = Verifier::verifyFromRequest(POSITIVE_CARDINAL_NUMBER, 'round', false);
  59. $user = Verifier::verifyFromRequest(NOT_NULL_STRING, 'user', false);
  60.  
  61. if (($user && $this->checkUser($user)) || !$user) {
  62.  
  63. $score = $this->_getScore();
  64. $this->t->assign('rounds', $this->_getRoundsList());
  65. $this->t->assign('types', $this->_getTypes());
  66. $this->t->assign('score', $score);
  67. }
  68.  
  69. $this->t->assign('user', $user);
  70. $this->t->assign('roundId', $this->roundId);
  71. $this->t->assign('STATUS', $this->status);
  72. $this->t->assign('LOGOUT', Typer_Auth::isUserLogged());
  73. return $this->t->fetch('stats_user.ihtml');
  74. }
  75.  
  76. function _getScore() {
  77. $roundId = $this->roundId;
  78. if (! $roundId) {
  79. $roundId = $this->checkRound();
  80. }
  81.  
  82. $points = $this->q->getPoints();
  83. if ( !$points) {
  84. return false;
  85. }
  86.  
  87. if ( !$this->User) {
  88. $userData = Typer_Auth::getLoggedUserData();
  89. }
  90. else {
  91. $userData = $this->User;
  92. }
  93.  
  94.  
  95. $score = 0;
  96. $sql = "SELECT * FROM styper_type t LEFT JOIN styper_match m ON t.matchid = m.matchid LEFT JOIN styper_round r ON r.roundid = m.roundid WHERE t.userid = '{$userData['userid']}' AND r.roundclosed = 1 AND r.roundid <= '{$roundId}' AND r.rounddeleted = 0 ORDER BY r.roundid";
  97. $types = $this->db->table($sql);
  98.  
  99. /*
  100. * rozliczenie za zgodnosc typu z wynikiem
  101. */
  102. foreach ($types as $tkey => $tval) {
  103.  
  104. if ( empty($tval['matchhost']) && empty($tval['matchguest']) ) {
  105. continue;
  106. }
  107. if ($tval['matchhostscore'] == $tval['typehost'] && $tval['matchguestscore'] == $tval['typeguest']) {
  108. //echo "bullseye!";
  109. $score += $points['shot'];
  110. }
  111. else if($tval['matchhostscore'] - $tval['typehost'] == $tval['matchguestscore'] - $tval['typeguest']) {
  112. //echo "bramka";
  113. $score += $points['diff'];
  114. }
  115. else if(($tval['matchhostscore'] > $tval['matchguestscore']) && ($tval['typehost'] > $tval['typeguest']) || ($tval['matchhostscore'] < $tval['matchguestscore']) && ($tval['typehost'] < $tval['typeguest']) || ($tval['matchhostscore'] == $tval['matchguestscore']) && ($tval['typehost'] == $tval['typeguest'])) {
  116. //echo "strona";
  117. $score += $points['side'];
  118. }
  119.  
  120. if ($tval['matchspecial'])
  121. {
  122. $score += $points['round'];
  123. }
  124. }
  125.  
  126. return $score;
  127.  
  128. }
  129.  
  130. function _getRoundsList() {
  131.  
  132. $sql = "SELECT * FROM styper_round WHERE roundclosed = 1 AND roundactive = 0 AND rounddeleted = 0 ORDER BY roundid DESC";
  133.  
  134. $rounds = $this->db->table($sql);
  135. return $rounds;
  136. }
  137.  
  138. function _getTypes() {
  139.  
  140. if (! $this->User) {
  141. $userData = Typer_Auth::getLoggedUserData();
  142. }
  143. else {
  144. $userData = $this->User;
  145. }
  146.  
  147. $roundId = $this->roundId;
  148. if (!$roundId) {
  149.  
  150. $sql = "SELECT *, m.matchid as matchno, h.teamname as hostname, g.teamname as guestname FROM styper_match m LEFT JOIN styper_team h ON h.teamid = m.matchhost LEFT JOIN styper_team g ON g.teamid = m.matchguest LEFT JOIN (SELECT * FROM styper_type WHERE userid = '{$userData['userid']}') t ON m.matchid = t.matchid LEFT JOIN styper_round r ON m.roundid = r.roundid WHERE r.roundclosed = 0 AND r.roundactive = 1";
  151. $res = $this->db->table($sql);
  152. $this->status = textSys('stats:AKTUALNA_NIEPELNA_SYTUACJA');
  153. return $res;
  154. }
  155.  
  156. $sql = "SELECT *, m.matchid as matchno, h.teamname as hostname, g.teamname as guestname FROM styper_match m LEFT JOIN styper_team h ON h.teamid = m.matchhost LEFT JOIN styper_team g ON g.teamid = m.matchguest LEFT JOIN (SELECT * FROM styper_type WHERE userid = '{$userData['userid']}') t ON m.matchid = t.matchid LEFT JOIN styper_round r ON m.roundid = r.roundid WHERE m.roundid = '{$roundId}' AND r.roundclosed = 1 AND m.matchplayed = 1";
  157. $types = $this->db->table($sql);
  158.  
  159. return $types;
  160. }
  161.  
  162. }
ucho
Skoro to gotowy skrypt to nie ma sensu żebyś go poprawiał. Znajdź miejsce w kodzie gdzie jest tworzony obiekt Smarty ( przy odrobinie szczęścia będzie tylko jedno takie miejsce) i zrób costakiego:
  1. $smarty = new Smarty(); // tego szukasz
  2. $smarty->error_reporting = E_ALL & ~E_NOTICE;// to dopisujesz

Oczywiście nazwa zmiennej może być inna niż '$smarty', sam musisz poszukać.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.