Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem Z Wyświetlaniem Wyniku
Forum PHP.pl > Forum > Przedszkole
MoD
Mam taki kod:
  1. <?php
  2.     require_once( 'includes/sql_functions.inc.php' );
  3.     require_once( 'includes/session.inc.php' );
  4.     
  5.     CheckSession();
  6.     Connect();
  7.     
  8.     print 'Zapytanie SQL:<br>';
  9.     
  10.     require_once( 'includes/sql_form.inc.php' );
  11.     
  12.     if ( $_POST['sql'] )
  13.     {
  14.         if ( ereg( '^SELECT', $_POST['sql'] ) || ereg( '^select', $_POST['sql'] ) )
  15.         {
  16.             $tablename = Table( $_POST['sql'] );
  17.             
  18.             $result = mysql_query( $_POST['sql'] ) or die( 'MySQL zwrócił komunikat: '.mysql_error() );
  19.             
  20.             print '<br>';
  21.             print '<table border=1>';
  22.             print '<tr>';
  23.             
  24.             $fields = mysql_list_fields('database', $tablename);
  25.             
  26.             for ( $i=0; $i<count($fields); $i++ )
  27.             {
  28.                 print '<td><b>'.$fields[$i].'</b></td>';
  29.             }
  30.             
  31.             print '</tr>';
  32.             print '<tr>';
  33.             
  34.             while ( $row = mysql_fetch_array( $result ) )
  35.             {
  36.                 for ( $j=0; $j<count($result); $j++ )
  37.                 {
  38.                     print '<td>'.$row[$j].'</td>';
  39.                 }
  40.             }
  41.             
  42.             print '</tr>';
  43.             print '</table>';
  44.         }
  45.         else
  46.         {
  47.             mysql_query( $_POST['sql'] ) or die( 'MySQL zwrócił komunikat: '.mysql_error() );
  48.         }
  49.     }
  50.     
  51.     print '</center>';
  52.     
  53. ?>

Jak wpiszę zapytanie 'select * from tabela' to powinno mi wyświetlić nazwy pól i ich wartości, a nie wyświetla nic sad.gif Pomóżcie mi!
Z góry dziękuję.
sf
Hm, a jaki błąd wyświetla? W ogóle to sobie poprostu upraszczaj kod poprzez użycie komentarzy /* */ aż znajdziesz to co jest nie tak.
MoD
Kłopot w tym, że nie wyświetla nic :/, nie wiem czemu. Tabela jest, baza danych też.
itsme
Cytat(MoD @ 2004-08-24 19:08:21)
Kłopot w tym, że nie wyświetla nic :/, nie wiem czemu. Tabela jest, baza danych też.

  1. <?php
  2. require_once( 'includes/sql_functions.inc.php' );
  3. require_once( 'includes/session.inc.php' );
  4.  
  5. CheckSession();
  6. Connect();
  7. echo &#092;"1\";
  8. print 'Zapytanie SQL:<br>';
  9.  
  10. require_once( 'includes/sql_form.inc.php' );
  11.  
  12. if ( $_POST['sql'] )
  13. {
  14. echo &#092;"2\";
  15. if ( ereg( '^SELECT', $_POST['sql'] ) || ereg( '^select', $_POST['sql'] ) )
  16. {
  17.  echo &#092;"3\";
  18.  $tablename = Table( $_POST['sql'] );
  19.  
  20. $result = mysql_query( $_POST['sql'] ) or die( 'MySQL zwrócił komunikat: '.mysql_error() );
  21.  
  22. print '<br>';
  23. print '<table border=1>';
  24. print '<tr>';
  25.  
  26. $fields = mysql_list_fields('database', $tablename);
  27.  
  28. for ( $i=0; $i<count($fields); $i++ )
  29. {
  30.  echo &#092;"4\";
  31.  print '<td><b>'.$fields[$i].'</b></td>';
  32. }
  33.  
  34. print '</tr>';
  35. print '<tr>';
  36.  
  37. while ( $row = mysql_fetch_array( $result ) )
  38. {
  39. echo &#092;"5\";
  40. for ( $j=0; $j<count($result); $j++ )
  41. {
  42.  echo &#092;"6\";
  43.  print '<td>'.$row[$j].'</td>';
  44. }
  45. }
  46.  
  47. print '</tr>';
  48. print '</table>';
  49. }
  50. else
  51. {
  52. mysql_query( $_POST['sql'] ) or die( 'MySQL zwrócił komunikat: '.mysql_error() );
  53. }
  54. }
  55.  
  56. print '</center>';
  57.  
  58. ?>
wklei sobie i zobacz na ktorej cyferce sie zatrzymuje swinskie ale skuteczne
MoD
Hmmm jak wywołałem zapytanie 'select * from news' to mi wyrzuciło 33 linie '56' a poniżej tabelkę z pokolei napisanymi liczbami od 1 do 33 sad.gif

---

Ok, już sobie poradziłem. Zamieniłem swój kod na ten z manuala smile.gif
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.