Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Stała szerokość tabeli
trebron
post 8.11.2022, 12:59:37
Post #1





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 8.11.2020

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


Witam. Mam problem z okładkami w tabeli. Mieści się na stronie 10 okładek w jednej lini i jest ok ale jak chce zmienić ilość okładek np na 100 i tym samym ustalić DESC LIMIT 100, to wszystkie plakaty zamiast nie poszerzać tabeli i kolejne okladki pojawiać się w nastepnej lini, mam wszystkie 100 okładek w jednej lini. Można prosić o pomoc, aby w jednej lini było max 10 okladek a reszta wędrowała w dół?

  1. $w_1 = "width=100%";
  2. print("<br /><br /><table $w_1 class='belkaGlownaTable' border='0' cellpadding='0' align='center'>");
  3. print("<tr>");
  4. print("<td class='belkaGlownaTd'>Najnowsze plakaty</td>");
  5. print("</tr>");
  6. print("</table>");
  7.  
  8. $query = "SELECT id, name, poster, added FROM filmy WHERE visible='yes' AND category='37' ORDER BY added DESC LIMIT 10";
  9. $result = $dbc_h->query($query);
  10.  
  11. print("<table $w_1 class='text' border='0' cellspacing='1' cellpadding='0'></tr>");
  12. while ($row = mysqli_fetch_assoc($result))
  13. {
  14. $id = $row['id'];
  15. $name = $row['name'];
  16. $poster = $row['poster'];
  17. $hits = $row['added'];
  18. print("<td class='image_poster'><a href=$BASEURL/details.php?id=$id title=\"$name\"><img src=".$row["poster"]." width=\"80\" height=\"110\" title=\"$name\" style='border:1px solid #000;' class='okladkabig'/></a><br /><b>dodano:</b>&nbsp;&nbsp;<span class='dodano'>$hits</span></td>");
  19. }
  20. print("</tr></table>");
Go to the top of the page
+Quote Post
trueblue
post 8.11.2022, 13:01:50
Post #2





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
Dołączył: 11.03.2014

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


Komórki w wierszu tabeli nie zawijają się.
Musisz po 10 komórkach tworzyć nowy wiersz.


--------------------
Go to the top of the page
+Quote Post
trebron
post 8.11.2022, 13:18:06
Post #3





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 8.11.2020

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


W jaki sposob powinienem to napisać? W przypadku jakbym ustawił okładki dodane w ostatnim miesiącu a było by ich sporo to muszę na sztywno wpisac ilość wierszy?
Go to the top of the page
+Quote Post
viking
post 8.11.2022, 13:47:12
Post #4





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


A po co je pchasz do tabeli. Zrób np grida.
https://css-tricks.com/snippets/css/complete-guide-grid/


--------------------
Go to the top of the page
+Quote Post
trebron
post 8.11.2022, 13:56:55
Post #5





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 8.11.2020

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


Chyba odpuszczę bo dla mnie za trudne sad.gif
Go to the top of the page
+Quote Post
viking
post 8.11.2022, 14:04:55
Post #6





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Za trudne czy za leniwy jesteś żeby chwilę poczytać?
https://jsfiddle.net/qbtvkcdm/


--------------------
Go to the top of the page
+Quote Post
trebron
post 8.11.2022, 14:23:11
Post #7





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 8.11.2020

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


Przeczytałem tylko aby to skleić razem mam problem.
Go to the top of the page
+Quote Post
Salvation
post 8.11.2022, 15:07:54
Post #8





Grupa: Zarejestrowani
Postów: 342
Pomógł: 70
Dołączył: 15.07.2014

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


Jak chcesz to ogarnąć w PHP, to podmień ostatnie linijki z tego kawałka kodu co wkleiłeś:
  1. print("<table $w_1 class='text' border='0' cellspacing='1' cellpadding='0'></tr>");
  2. while ($row = mysqli_fetch_assoc($result))
  3. {
  4. $id = $row['id'];
  5. $name = $row['name'];
  6. $poster = $row['poster'];
  7. $hits = $row['added'];
  8. print("<td class='image_poster'><a href=$BASEURL/details.php?id=$id title=\"$name\"><img src=".$row["poster"]." width=\"80\" height=\"110\" title=\"$name\" style='border:1px solid #000;' class='okladkabig'/></a><br /><b>dodano:</b>&nbsp;&nbsp;<span class='dodano'>$hits</span></td>");
  9. }
  10. print("</tr></table>");

Na to:
  1. $filmsInCategory = $result->fetch_all(MYSQLI_ASSOC);
  2. $filmsChunks = array_chunk($filmsInCategory, 10);
  3.  
  4. echo '<table ' . $w_1 . ' class="text" border="0" cellspacing="1" cellpadding="0">';
  5.  
  6. foreach ($filmsChunks as $chunk) {
  7. echo '<tr>';
  8.  
  9. foreach ($chunk as $row) {
  10. $id = $row['id'];
  11. $name = $row['name'];
  12. $poster = $row['poster'];
  13. $hits = $row['added'];
  14. $href = sprintf('%s/details.php?id=%d', $BASEURL, $id);
  15.  
  16. echo '<td class="image_poster">
  17. <a href="' . $href . '" title="' . $name . '">
  18. <img src="' . $poster . '" width="80" height="110" title="' . $name . '" style="border:1px solid #000;" class="okladkabig" />
  19. </a><br/>
  20. <b>dodano:</b>&nbsp;&nbsp;<span class="dodano">' . $hits . '</span>
  21. </td>';
  22. }
  23.  
  24. echo '</tr>';
  25. }
  26.  
  27. echo '</table>';


Ten post edytował Salvation 8.11.2022, 15:14:42
Go to the top of the page
+Quote Post
trebron
post 9.11.2022, 00:13:08
Post #9





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 8.11.2020

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


Cytat(Salvation @ 8.11.2022, 15:07:54 ) *
Jak chcesz to ogarnąć w PHP, to podmień ostatnie linijki z tego kawałka kodu co wkleiłeś:

Zrobłem tak jak pisałeś ale mam pusty wynik.
Go to the top of the page
+Quote Post
viking
post 9.11.2022, 06:01:53
Post #10





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


A dlaczego nie zrobisz tak jak napisałem? Masz 4 linijki w css i prosty html.


--------------------
Go to the top of the page
+Quote Post
trebron
post 9.11.2022, 09:31:08
Post #11





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 8.11.2020

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


Cytat(viking @ 9.11.2022, 06:01:53 ) *
A dlaczego nie zrobisz tak jak napisałem? Masz 4 linijki w css i prosty html.

Zrobiłem tak jak poniżej i teraz mam 10 wersów po jednej okładce
  1. print("<div $w_1 class='text' border='0' cellspacing='1' cellpadding='0'>");
  2. while ($row = mysqli_fetch_assoc($result))
  3. {
  4. $id = $row['id'];
  5. $name = $row['name'];
  6. $poster = $row['poster'];
  7. $hits = $row['added'];
  8. print("<div class='container'>");
  9. print("<div class='image_poster'><a href=$BASEURL/details.php?id=$id title=\"$name\"><img src=".$row["poster"]." width=\"80\" height=\"110\" title=\"$name\" style='border:1px solid #000;' class='okladkabig'/></a><br /><b>dodano:</b>&nbsp;&nbsp;<span class='dodano'>$hits</span></div>");
  10. print("</div>");
  11. }
  12. print("</div>");

Go to the top of the page
+Quote Post
trueblue
post 9.11.2022, 09:33:50
Post #12





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
Dołączył: 11.03.2014

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


A nie zauważyłeś, że w kodzie, który podał Viking, jest tylko jeden container?


--------------------
Go to the top of the page
+Quote Post
trebron
post 9.11.2022, 10:08:02
Post #13





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 8.11.2020

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


Mam pierwsze efekty i jest w kazdym wersie po 10 smile.gif Tylko nie wiem dlaczego 2 razy dodając container wyswietla się prawidlowo. Drugi problem, że nie jest na środku tylko z lewej. Może to w inny sposob musi być wpisane z tym container? Przepraszam ale jestem przedszkolakiem i cięzko mi to ogarnąć smile.gif
  1. print("<div class='container'>");
  2. while ($row = mysqli_fetch_assoc($result))
  3. {
  4. $id = $row['id'];
  5. $name = $row['name'];
  6. $poster = $row['poster'];
  7. $hits = $row['added'];
  8. print("<div class='container'>");
  9. print("<div class='image_poster'><a href=$BASEURL/details.php?id=$id title=\"$name\"><img src=".$row["poster"]." width=\"80\" height=\"110\" title=\"$name\" style='border:1px solid #000;' class='okladkabig'/></a><br /><b>dodano:</b>  <span class='dodano'>$hits</span></div>");
  10. print("</div>");
  11. }


Ten post edytował trebron 9.11.2022, 10:12:09
Go to the top of the page
+Quote Post
trueblue
post 9.11.2022, 10:09:48
Post #14





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
Dołączył: 11.03.2014

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


W sumie to niewiele zmieniłeś, teraz jest container przy każdym posterze i na całość.


--------------------
Go to the top of the page
+Quote Post
viking
post 9.11.2022, 10:15:06
Post #15





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


A poza tym nic nie czytasz? https://developer.mozilla.org/en-US/docs/We...CSS_Grid_Layout
Ustawianie w grid czy flex jest bardzo proste.


--------------------
Go to the top of the page
+Quote Post
trebron
post 9.11.2022, 10:18:28
Post #16





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 8.11.2020

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


A więc usunąłem tego przed posterem i </div> dałem poza pętlę bo przedtem tak nie zrobilem i nie wyświetlało się prawidłowo, a teraz nawet wyśrodkowało się. Dziękuję za pomoc, problem rozwiązany, uff:)
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: 19.04.2024 - 11:28