Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Nazwa pola mysql
WebKing
post
Post #1





Grupa: Zarejestrowani
Postów: 219
Pomógł: 16
Dołączył: 16.07.2007

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


Cześć,
Chciałbym z bazy danych wyciągnąć nazwe pola a obok zawartość z niej. A oto mój kod:
  1. <?php
  2.    $link = mysql_connect("localhost", "root", "");
  3.    $fields = mysql_list_fields("test", "test");
  4.    $columns = mysql_num_fields($fields);
  5.    $result = mysql_query("SELECT * FROM test");
  6.    $x = 0;
  7.    while ($row = mysql_fetch_array($result)) {
  8.        for ($i=0; $i<$columns; $i++) {
  9.            $field[$i] = mysql_field_name($fields, $i);
  10.        }
  11.        echo $field[$x]."-".$row[$field[$x]];
  12.        $x++;
  13.    }
  14. ?>


Chciałbym aby zostało wyświetlone:
id - 1
name - cos1
pass - haslo1

id - 2
name - cos2
pass - haslo2

Mój kod wyświetla tylko jeden rekord, proszę o pomoc winksmiley.jpg
Go to the top of the page
+Quote Post
Heres
post
Post #2





Grupa: Zarejestrowani
Postów: 12
Pomógł: 1
Dołączył: 4.07.2003

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


spróbuj coś takiego:

  1. <?php
  2.   $link = mysql_connect("localhost", "root", "");
  3.   $fields = mysql_list_fields("test", "test");
  4.   $columns = mysql_num_fields($fields);
  5.   $result = mysql_query("SELECT * FROM test");
  6.   $x = 0;
  7.   while ($row = mysql_fetch_array($result)) {
  8.       for ($i=0; $i<$columns; $i++) {
  9.           $field[$i] = mysql_field_name($fields, $i);
  10.           echo $field[$i]."-".$row[$field[$i]];
  11.       }
  12.      
  13.       $x++;
  14.   }
  15. ?>


pozdr

Ten post edytował Heres 3.01.2009, 14:29:56


--------------------
Łukasz Kaczyński
Website: Heres
GG; 7979914, JID: Heres[at]chrome.pl
Go to the top of the page
+Quote Post
legorek
post
Post #3





Grupa: Zarejestrowani
Postów: 411
Pomógł: 35
Dołączył: 27.06.2004
Skąd: Kraków

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


  1. <?php
  2. $link = mysql_connect("localhost", "root", "");
  3. $fields = mysql_list_fields("test", "test");
  4. $columns = mysql_num_fields($fields);
  5. $result = mysql_query("SELECT * FROM test");
  6. while ($row = mysql_fetch_assoc($result)) {
  7. foreach ($row as $key => $value) {
  8. echo $key.' - '.$value;
  9. }
  10. }
  11. ?>


--------------------
Go to the top of the page
+Quote Post
WebKing
post
Post #4





Grupa: Zarejestrowani
Postów: 219
Pomógł: 16
Dołączył: 16.07.2007

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


Działa, dzieki
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 Aktualny czas: 21.08.2025 - 21:53