Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> porównywanie elementów
przonak007
post 24.05.2020, 22:10:09
Post #1





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 4.06.2012

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


Cześć,
muszę zrobić stronę w oparciu o wordpressa dot. porównywarki komputerów. Dodać mogę około 5/6 elementów.
Mam problem z wyświetleniem zawartości na stronie. Chciałbym mieć na samym początku tabelę z informacjami a do tych informacji będą dodawane informacje o wybranych elementach . Poniżej przedstawiam o co chodzi. Czy podpowie mi ktoś jak można uzyskać ten efekt?

Nazwa komputera |Dell model V330 | HP Probook
Procesor | Intel i5| Intel i7
Rodzaj dysku | SSD |HDD

Zrobiłem coś takiego, ale wszytsko jest w jednej kolumnie zamiast układać się z boku.
  1. <?php
  2. include 'wp-content/DBController.php';
  3. $db_handle = new DBController();
  4. $countryResult = $db_handle->runQuery("SELECT DISTINCT Country FROM tbl_user ORDER BY Country ASC");
  5. ?>
  6. <html>
  7. <head>
  8. <link href="style.css" type="text/css" rel="stylesheet" />
  9. <title>Multiselect Dropdown Filter</title>
  10. </head>
  11. <body>
  12. <h2>Multiselect Dropdown Filter</h2>
  13. <form method="POST" name="search" action="index.php">
  14. <div id="demo-grid">
  15. <div class="search-box">
  16. <select id="Place" name="country[]" multiple="multiple">
  17. <option value="0" selected="selected">Select Country</option>
  18. <?php
  19. if (! empty($countryResult)) {
  20. foreach ($countryResult as $key => $value) {
  21. echo '<option value="' . $countryResult[$key]['Country'] . '">' . $countryResult[$key]['Country'] . '</option>';
  22. }
  23. }
  24. ?>
  25. </select><br> <br>
  26. <button id="Filter">Search</button>
  27. </div>
  28.  
  29. <?php
  30. if (! empty($_POST['country'])) {
  31. ?>
  32. <table cellpadding="10" cellspacing="1">
  33.  
  34. <thead>
  35. <tr>
  36. <td><strong>Name1</strong></td>
  37. </tr>
  38. <tr>
  39. <td><strong>Gender</strong></td>
  40. </tr>
  41. <tr>
  42. <td><strong>Country</strong></td>
  43. </tr>
  44. </thead>
  45. <tbody>
  46. <?php
  47. $query = "SELECT * from tbl_user";
  48. $i = 0;
  49. $selectedOptionCount = count($_POST['country']);
  50. $selectedOption = "";
  51. while ($i < $selectedOptionCount) {
  52. $selectedOption = $selectedOption . "'" . $_POST['country'][$i] . "'";
  53. if ($i < $selectedOptionCount - 1) {
  54. $selectedOption = $selectedOption . ", ";
  55. }
  56.  
  57. $i ++;
  58. }
  59. $query = $query . " WHERE country in (" . $selectedOption . ")";
  60.  
  61. $result = $db_handle->runQuery($query);
  62. }
  63. if (! empty($result)) {
  64. foreach ($result as $key => $value) {
  65. ?>
  66. <tr>
  67. <td><div class="col" id="user_data_1"><?php echo $result[$key]['Name']; ?></div></td>
  68. </tr>
  69. <tr>
  70. <td><div class="col" id="user_data_2"><?php echo $result[$key]['Gender']; ?> </div></td>
  71. </tr>
  72. <tr>
  73. <td><div class="col" id="user_data_3"><?php echo $result[$key]['Country']; ?> </div></td>
  74. </tr>
  75.  
  76. <?php
  77. }
  78. ?>
  79.  
  80. </tbody>
  81. </table>
  82. <?php
  83. }
  84. ?>
  85. </div>
  86. </form>
  87. </body>
  88. </html>




Go to the top of the page
+Quote Post
Tomplus
post 28.05.2020, 05:20:08
Post #2





Grupa: Zarejestrowani
Postów: 1 828
Pomógł: 225
Dołączył: 20.03.2005
Skąd: Będzin

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


Tak w wielkim skrócie:
  1. foreach($komputery['nazwa'] as $komputer) {
  2.  
  3. echo "<td>";
  4. echo $komputer;
  5. echo "</td>";
  6.  
  7. }


Albo robisz to w DIVach, tylko stylujesz odpowiednio display: table ...
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: 28.03.2024 - 13:56