Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Wstawienie lp do tabeli przy pobieranych danych
Dominator
post
Post #1





Grupa: Zarejestrowani
Postów: 565
Pomógł: 15
Dołączył: 11.10.2010

Ostrzeżenie: (20%)
X----


Witam,
pobieram sobie informacje z bazy danych:

  1. while($details = $stmt->fetch())
  2. {
  3. echo "<tr>
  4. <td class='text-center'>1</td>
  5. <td class='text-center'><img src='http://cravatar.eu/helmavatar/".$details["owner"]."/64.png' class='avatar' /> </td>
  6. <td class='text-center'><a href='gildiaInfo.php?guild=".$details["name"]."'>".$details["name"]."</a> </td>
  7. <td class='text-center'><a href='gildiaInfo.php?guild=".$details["name"]."'>".$details["tag"]."</a>
  8. </td>
  9. <td class='text-center'>".$details["points"]."</td>
  10. <td class='text-center'>".$details["owner"]."</td>
  11. <td class='text-center'>".$this->countGuildMembers($details["name"])."</td>
  12. </tr>";
  13. }


Mam 100 rekordów i wyświetla się to w taki sposób:

1. tekst1
1. tekst2
1. tekst3
1. tekst4
1. tekst5

itd...

jak zrobić coś takiego żeby się wyświetlało tak:

1. tekst1
2. tekst2
3. tekst3
4. tekst4

itd...

Próbowałem z wstawianiem for, ale jakoś nie wychodziło..
Go to the top of the page
+Quote Post
rad11
post
Post #2





Grupa: Zarejestrowani
Postów: 1 270
Pomógł: 184
Dołączył: 7.10.2012
Skąd: Warszawa

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


  1. $i = 0;
  2. while($details = $stmt->fetch())
  3. {
  4. echo "<tr>
  5. <td class='text-center'>$i</td>
  6. <td class='text-center'><img src='http://cravatar.eu/helmavatar/".$details["owner"]."/64.png' class='avatar' /> </td>
  7. <td class='text-center'><a href='gildiaInfo.php?guild=".$details["name"]."'>".$details["name"]."</a> </td>
  8. <td class='text-center'><a href='gildiaInfo.php?guild=".$details["name"]."'>".$details["tag"]."</a>
  9. </td>
  10. <td class='text-center'>".$details["points"]."</td>
  11. <td class='text-center'>".$details["owner"]."</td>
  12. <td class='text-center'>".$this->countGuildMembers($details["name"])."</td>
  13. </tr>";
  14. $i++;
  15.  
  16. }
Go to the top of the page
+Quote Post
trueblue
post
Post #3





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


http://jsfiddle.net/y0m3ooxv/
Go to the top of the page
+Quote Post
sadistic_son
post
Post #4





Grupa: Zarejestrowani
Postów: 1 495
Pomógł: 245
Dołączył: 1.07.2009
Skąd: Bydgoszcz

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


@rad11 jak już to $i=1; na starcie, bo ma zaczynać od 1 a nie od 0. Ach, te przyzwyczajenia... (IMG:style_emoticons/default/tongue.gif)

Ten post edytował sadistic_son 7.05.2015, 13:09:23
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 27.09.2025 - 12:37