Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php] nie dzialajaca petla w klasie
Forum PHP.pl > Forum > Przedszkole
Balon
  1. <?php
  2. /**
  3.  * Staty postaci
  4.  *
  5.  * @var array
  6.  */
  7. var $arrChar = array();
  8. /**
  9.  * Staty potwora
  10.  *
  11.  * @var array
  12.  */
  13. var $arrMob = array();
  14. (...)
  15. /**
  16.  * Pobieranie danych z bazy Mysql
  17.  *
  18.  */
  19. function getvalues()
  20. {
  21. db_connect();
  22. // zycie potwora i usera oraz id potwora
  23. $this->strQuery = "SELECT * FROM fight WHERE id_user = '".$this->intId."' LIMIT 1;";
  24. $this->mixResult = mysql_query( $this->strQuery );
  25. while( $this->arrRow = mysql_fetch_array( $this->mixResult ) )
  26. {
  27. $this->arrChar['HP'] = $this->arrRow['hp_char'];
  28. $this->arrMob['HP'] = $this->arrRow['hp_mob'];
  29. $this->intMob = $this->arrRow['id_mob'];
  30. }
  31. // staty usera
  32. $this->strQuery = "SELECT * FROM stats WHERE user = '".$this->intId."' LIMIT 1;";
  33. $this->mixResult = mysql_query( $this->strQuery );
  34. while( $this->arrRow = mysql_fetch_array( $this->mixResult ) )
  35. {
  36. $this->arrChar['MP'] = $this->arrRow['mp'];
  37. $this->arrChar['STR'] = $this->arrRow['str'];
  38. $this->arrChar['INT'] = $this->arrRow['int'];
  39. $this->arrChar['DEF'] = $this->arrRow['def'];
  40. $this->arrChar['AGI'] = $this->arrRow['agi'];
  41. $this->arrChar['CEL'] = $this->arrRow['cel'];
  42. }
  43. // Staty potwora
  44. $this->sql_cache('mob_'.$this->intMob.'');
  45. $this->sql_query ("SELECT lvl, mp, str, `int`, def, agi, cel FROM mobs WHERE id = '".$this->intMob."' ORDER BY id LIMIT 1");
  46. while( $this->sql_fetch_row() )
  47. {
  48. $this->arrMob['LVL'] = $this->rows[0];
  49. $this->arrMob['MP'] = $this->rows[1];
  50. $this->arrMob['STR'] = $this->rows[2];
  51. $this->arrMob['INT'] = $this->rows[3];
  52. $this->arrMob['DEF'] = $this->rows[4];
  53. $this->arrMob['AGI'] = $this->rows[5];
  54. $this->arrMob['CEL'] = $this->rows[6];
  55. }
  56. $this->sql_cache();
  57. // skill
  58. if( $this->intIdSkill !== null ){
  59. $this->strQuery = "SELECT * FROM inventory WHERE id_skill = '".$this->intIdSkill."' AND type = 'skill' AND id_user = '".$this->intId."';";
  60. $this->mixResult = mysql_query( $this->strQuery );
  61. while( $this->arrRow = mysql_fetch_arrau( $this->mixResult ) )
  62. {
  63. $this->arrSkill['HP'] = $this->arrRow['hp'];
  64. $this->arrSkill['MP'] = $this->arrRow['mp'];
  65. $this->arrSkill['STR'] = $this->arrRow['str'];
  66. $this->arrSkill['INT'] = $this->arrRow['int'];
  67. $this->arrSkill['DEF'] = $this->arrRow['def'];
  68. $this->arrSkill['AGI'] = $this->arrRow['agi'];
  69. $this->arrSkill['CEL'] = $this->arrRow['cel'];
  70. }
  71. }
  72. ### test ###
  73. echo 'Postac:';
  74. while( list( $klucz, $wartosc ) = each( $this->arrChar ) ) 
  75. {
  76.  echo "Klucz => ".$klucz.", Wartosc => ".$wartosc."<br/>";
  77. }
  78. echo '<br/>';
  79. echo 'Potwor:';
  80. while( list( $klucz, $wartosc ) = each( $this->arrMob ) ) 
  81. {
  82. echo "Klucz => ".$klucz.", Wartosc => ".$wartosc."<br/>";
  83. }
  84. }
  85. ?>

chodzi mi o ten moment na koncu (test) ale dalem cala funkcje zeby nbyl wglad do wszystkiego co zwiazane z tym czyms

no i problem jest taki ze ten 'test' nie dziala .... bo praktycznie wywolujac ta funkcje powinien sie on wykonac, a tak sie nie dzieje
  1. <?php
  2. $fight = new fight;
  3. $fight->getvalues();
  4. ?>

dlaczego tak sie nie dzieje ?
Fipaj
  1. <?php
  2. while( list( $klucz, $wartosc ) = each( $this->arrChar ) )
  3. ?>


O foreach słyszałeś? Szybsze i bardziej elaganckie ;-)
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.