Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][MYSQL]Warning: Invalid argument supplied for foreach() on line 25
marcin86s
post
Post #1





Grupa: Zarejestrowani
Postów: 58
Pomógł: 0
Dołączył: 29.11.2007
Skąd: City 17

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


Kod wygląda tak:
  1. $g_link = false;
  2.  
  3. function GetMyConnection()
  4. {
  5. global $g_link;
  6. if( $g_link )
  7. return $g_link;
  8. $g_link = mysql_connect( 'localhost', 'root', '') or die('Could not connect to server.' );
  9. mysql_select_db('baza', $g_link) or die('Could not select database.');
  10. return $g_link;
  11. }
  12.  
  13. function CleanUpDB()
  14. {
  15. global $g_link;
  16. if( $g_link != false )
  17. mysql_close($g_link);
  18. $g_link = false;
  19. }
  20.  
  21. $results = mysql_query("SELECT * FROM tab", GetMyConnection() );
  22.  
  23. var_dump($results);
  24.  
  25. foreach ($results as $result){
  26. echo $result->date2;
  27. }

Tablica tak:
  1. CREATE TABLE IF NOT EXISTS `tab` (
  2. `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  3. `date2` int(100) DEFAULT NULL,
  4. PRIMARY KEY (`id`)
  5. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=60 ;
  6.  
  7. INSERT INTO `tab` (`id`, `date2`) VALUES
  8. (1, 1263855600),
  9. (2, 1263250800);

Błąd jest taki:
Cytat
Warning: Invalid argument supplied for foreach() on line 25

Co robię źle? Chce po prostu wyświetlić wszystkie wpisy z tabeli.

Ten post edytował marcin86s 13.11.2011, 14:33:55
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 Aktualny czas: 19.08.2025 - 18:29