Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL][PHP] Błąd z pokazaniem tabeli
-Mąka-
post 4.02.2012, 09:13:43
Post #1





Goście







Witam mam dosyć ciekawy błąd , a dokładniej nie chce odczytać danych z mysql i pokazać je w postaci tabeli .
Oto kod :
  1. <?
  2. header('Content-Type: text/html; charset=utf-8');
  3. ?>
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  7. <title>Banned Players of server</title>
  8. </head>
  9. <body>
  10. <?php
  11. // change these things
  12. $server = "www.mcpl.net.pl";
  13. $dbuser = "admin";
  14. $dbpass = "admin1";
  15. $dbname = "mcpl";
  16.  
  17. mysql_connect($server, $dbuser, $dbpass);
  18. mysql_select_db($dbname);
  19. $result = mysql_query("SELECT * FROM banlist ORDER BY time DESC");
  20. echo "<table width=70% border=1 cellpadding=5 cellspacing=0>";
  21. echo "<tr style=\"font-weight:bold\">
  22. <td>Name</td>
  23. <td>Reason</td>
  24. <td>Admin/Mod</td>
  25. <td>Time of ban</td>
  26. <td>Time of unban</td>
  27. </tr>";
  28. while($row = mysql_fetch_assoc($result)){
  29. if($col == "#eeeeee"){
  30. $col = "#ffffff";
  31. }else{
  32. $col = "#eeeeee";
  33. }
  34. echo "<tr bgcolor=$col>";
  35. echo "<td>".$row['name']."</td>";
  36. echo "<td>".$row['reason']."</td>";
  37. echo "<td>".$row['admin']."</td>";
  38. echo "<td>".date("d M, Y g:ia",$row['time'])."</td>";
  39. if($row['temptime'] == "0"){
  40. echo "<td>∞</td>";
  41. }else{
  42. echo "<td>".date("d M, Y g:ia",$row['temptime'])."</td>";
  43. }
  44. echo "</tr>";
  45. }
  46. echo"</table>"
  47. ?>
  48. </body></html>


SQL:
  1. CREATE TABLE `banlist` (
  2. `name` varchar(32) NOT NULL,
  3. `reason` text NOT NULL,
  4. `admin` varchar(32) NOT NULL,
  5. `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  6. `temptime` TIMESTAMP NOT NULL ,
  7. PRIMARY KEY (`name`)
  8. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Niestety jak wchodzę na stronę widzę tylko to :
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/1/public_html/b.php on line 34
Czy ktoś może mi w tym pomóc questionmark.gif smile.gif
Powód edycji: [Ociu]: Poprawiłem bbCode
Go to the top of the page
+Quote Post
bzeebzee
post 4.02.2012, 09:20:52
Post #2





Grupa: Zarejestrowani
Postów: 38
Pomógł: 3
Dołączył: 25.12.2011

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


  1. // daj tak
  2. $result = mysql_query("SELECT * FROM banlist ORDER BY time DESC") or die(mysql_error());
Go to the top of the page
+Quote Post
-Mąka-
post 4.02.2012, 09:33:32
Post #3





Goście







Jak tak zrobiłem to teraz mam No database selected
Go to the top of the page
+Quote Post
Ociu
post 4.02.2012, 09:36:02
Post #4





Grupa: Moderatorzy
Postów: 1 566
Pomógł: 37
Dołączył: 14.05.2003
Skąd: Kraków




Sprawdź czy nie walnąłeś się w nazwie bazy, którą wybierasz.
Go to the top of the page
+Quote Post
-Mąka-
post 4.02.2012, 09:41:18
Post #5





Goście







Nie dobrze wpisałem wszystkie dane .
Go to the top of the page
+Quote Post
pianta_d
post 4.02.2012, 10:46:50
Post #6





Grupa: Zarejestrowani
Postów: 176
Pomógł: 18
Dołączył: 5.01.2007

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


Witam

Problem Twój rozwiązał @bzeebzee
Nie masz takiej tabeli w bazie. Może walnąłeś się w nazwie tabeli (sprawdziłem to na swoim localu)

Pozdrawiam

EDIT

Na moim kompie działa
  1. <?
  2. header('Content-Type: text/html; charset=utf-8');
  3. ?>
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  7. <title>Banned Players of server</title>
  8. </head>
  9. <body>
  10. <?php
  11. // change these things
  12. $server = "localhost";
  13. $dbuser = "root";
  14. $dbpass = "vertrigo";
  15. $dbname = "temp";
  16.  
  17. mysql_connect($server, $dbuser, $dbpass);
  18. mysql_select_db($dbname);
  19. echo "<table width=70% border=1 cellpadding=5 cellspacing=0>";
  20. $result = mysql_query("SELECT * FROM `banlist` ORDER BY `time` DESC") or die(mysql_error());
  21.  
  22. echo "<tr style=\"font-weight:bold\">
  23. <td>Name</td>
  24. <td>Reason</td>
  25. <td>Admin/Mod</td>
  26. <td>Time of ban</td>
  27. <td>Time of unban</td>
  28. </tr>";
  29. while($row = mysql_fetch_assoc($result))
  30.  
  31. {
  32. if($col == "#eeeeee"){
  33. $col = "#ffffff";
  34. }else{
  35. $col = "#eeeeee";
  36. }
  37. echo "<tr bgcolor=$col>";
  38. echo "<td>".$row['name']."</td>";
  39. echo "<td>".$row['reason']."</td>";
  40. echo "<td>".$row['admin']."</td>";
  41. echo "<td>".date("d M, Y g:ia",$row['time'])."</td>";
  42. if($row['temptime'] == "0"){
  43. echo "<td>∞</td>";
  44. }else{
  45. echo "<td>".date("d M, Y g:ia",$row['temptime'])."</td>";
  46. }
  47. echo "</tr>";
  48. }
  49. echo"</table>"
  50. ?>
  51. </body></html>


Ten post edytował pianta_d 4.02.2012, 10:49:54
Go to the top of the page
+Quote Post

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: 12.06.2025 - 17:54