Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php]Błąd z foreach
Mike122
post
Post #1





Grupa: Zarejestrowani
Postów: 253
Pomógł: 1
Dołączył: 12.04.2006

Ostrzeżenie: (0%)
-----


Witam napisałem skrypt:
  1. <?php
  2. $tablica_from = array();
  3. $tablica_from['pl'] = 'Polska';
  4. $tablica_from['de'] = 'Niemcy';
  5. $tablica_from['cz'] = 'Czechy';
  6. $tablica_from['uk'] = 'Wileka Brytania';
  7. $tablica_from['us'] = 'US';
  8. $tablica_from['ca'] = 'Kanada';
  9. $tablica_from['ru'] = 'Rosja';
  10. foreach ($tablica_from as $id => $id2){
  11. $rows = new Template($styl, 'menu.tmpl');
  12. $rows->add('id', $id);
  13. $rows->add('id2', $id2);
  14. $table .= $rows->execute();
  15. }
  16. ?>

I podczas wykonywania skryptu wywala błąd:

Notice: Undefined variable: table in home/httpd/newweb/panstwa.php on line 14


Czyli błąd tyczy się:
$table .= $rows->execute();
Jednak nie mogę usunąć "." ponieważ skrypt się nie wykona... Proszę o pomoc.
Go to the top of the page
+Quote Post
Cienki1980
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 1 590
Pomógł: 40
Dołączył: 11.01.2007
Skąd: Centrum

Ostrzeżenie: (0%)
-----


Przed foreachem zrób $tablica='';
Go to the top of the page
+Quote Post
Mike122
post
Post #3





Grupa: Zarejestrowani
Postów: 253
Pomógł: 1
Dołączył: 12.04.2006

Ostrzeżenie: (0%)
-----


~Cienki1980 możesz rowzinąć post bo niezbyt rozumie.
Jeżeli zrobiłem tak:
  1. <?php
  2. $tablica_from['ru'] = 'Rosja';
  3. $tablica_from ='';
  4. foreach ($tablica_from as $id => $id2){
  5. ?>


Warning: Invalid argument supplied for foreach() in home/httpd/newweb/panstwa.php on line 11

Notice: Undefined variable: table in home/httpd/newweb/subheader.php on line 16

Notice: Undefined index: menu in home/httpd/newweb/include/class.template.php(24) : regexp code on line 1

natomiast jeżeli tak:
  1. <?php
  2. $tablica_from['ru'] = 'Rosja';
  3. $tablica ='';
  4. foreach ($tablica_from as $id => $id2){
  5. ?>


Notice: Undefined variable: table in home/httpd/newweb/panstwa.php on line 14


Ten post edytował Mike122 31.01.2007, 21:07:51
Go to the top of the page
+Quote Post
Cienki1980
post
Post #4





Grupa: Przyjaciele php.pl
Postów: 1 590
Pomógł: 40
Dołączył: 11.01.2007
Skąd: Centrum

Ostrzeżenie: (0%)
-----


Sorry źle spojrzałem w kod.
Zrób przed foreachem ( nie musisz przed samym foreachem ) $table='';

To zapobiegnie pokazywaniu tego notica.
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 23.08.2025 - 04:05