Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL][PHP]Jak wyswietlic dane z bazy do tabelki
pkania128
post 25.01.2010, 11:55:30
Post #1





Grupa: Zarejestrowani
Postów: 27
Pomógł: 0
Dołączył: 3.07.2009

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


witam mam dane w tabeli i chcialbym je wyswietlic w tabelce na stronę
wyswietlam tak:

tekst 1
tekst 2
tekst 3
tekst 4

  1. <table width="50%" border="1" cellspacing="0" cellpadding="0">
  2. <tr>
  3. <td>tekst 1</td>
  4. </tr>
  5. <tr>
  6. <td>tekst 2</td>
  7. </tr>
  8. <tr>
  9. <td>tekst 3</td>
  10. </tr>
  11. <tr>
  12. <td>tekst 4</td>
  13. </tr>
  14. </table>


a chcialbym tak:

tekst 1 tekst 2
tekst 3 tekst 4

  1. <table width="50%" border="1" cellspacing="0" cellpadding="0">
  2. <tr>
  3. <td>tekst 1</td>
  4. <td>tekst 2</td>
  5. </tr>
  6. <tr>
  7. <td>tekst 3</td>
  8. <td>tekst 4</td>
  9. </tr>
  10. </table>


moje zapytanie do bazy

  1. $zapytanie = "select * from `baza` WHERE
  2. tekst like \"%$tekst%\"
  3. ORDER BY `id` DESC limit 0,4 ";
  4. for($i=0; $i<$ile; $i++){
  5. $wiersz = mysql_fetch_array($wynik);
  6. echo"<table width=\"440\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\">
  7. <tr>
  8. <td width=\"135\">";echo stripslashes($wiersz["tekst"]),"</td>
  9. </tr>
  10. </table>
  11.  
  12. ";
  13. }


z gory dzieki za pomoc
Go to the top of the page
+Quote Post
Ulysess
post 25.01.2010, 12:10:04
Post #2





Grupa: Zarejestrowani
Postów: 695
Pomógł: 65
Dołączył: 27.07.2009
Skąd: Y

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


hmm

  1. $zapytanie = "select * from `baza` WHERE tekst like \"%$tekst%\" ORDER BY `id` DESC limit 0,4";
  2. $wykonano_zapytanie = mysql_query($zapytanie) or die(mysql_error());
  3.  
  4. echo '<table width="440" border="0" cellspacing="2" cellpadding="0">';
  5. while($wiersz = mysql_fetch_assoc($wykonano_zapytanie))
  6. {
  7. echo '<tr><td width="135">'.stripslashes($wiersz['tekst']).'</td></tr>';
  8. }
  9. echo '</table>';


powinno działać , na szybkiego pisałem

Ten post edytował Ulysess 25.01.2010, 12:10:45
Go to the top of the page
+Quote Post
webspy
post 25.01.2010, 12:35:55
Post #3





Grupa: Zarejestrowani
Postów: 186
Pomógł: 9
Dołączył: 3.03.2008

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


A może tak:

  1. $p=0;
  2.  
  3. echo"<table width=\"440\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\">";
  4.  
  5. for($i=0; $i<$ile; $i++){
  6.  
  7. $wiersz = mysql_fetch_array($wynik);
  8.  
  9. if ($p == 0) echo "<tr>";
  10.  
  11. echo "<td width=\"135\">";echo stripslashes($wiersz["tekst"]),"</td>";
  12.  
  13. if ($p == 2) echo "</tr>";
  14.  
  15. $p++;
  16.  
  17. if ($p == 2) $p=0;
  18.  
  19. }
  20.  
  21. echo "</table>";


wiem, że to na piechotę ale działa smile.gif
Go to the top of the page
+Quote Post
pedro84
post 25.01.2010, 13:04:11
Post #4





Grupa: Nieautoryzowani
Postów: 2 249
Pomógł: 305
Dołączył: 2.10.2006

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


Powinieneś pętlę zrobić tak:

  1. while($row = mysql_fetch_assoc($query))
  2. {
  3. echo '<tr><td>$row['field1'])</td><td>$row['field2'])</td></tr>';
  4. }


--------------------
Google knows the answer...
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: 18.07.2025 - 04:40