Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL][PHP]Wykonanie kodu w zmiennej, PHP
extremist
post 22.01.2020, 17:43:31
Post #1





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 1.08.2019

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


Cześć,

mam problem, mam skrypt który wysyła maila. Skrypt działa, ale mam problem z wygenerowaniem tabeli w treści wiadomości. W zmiennej $mail chciałbym wrzucić poniższy kod który się wykona. Tak jak normalnie nie mam z tym problemu, po prostu wyświetlam poprzez echo, to w zmiennej gdy dochodzi do pętli skrypt przestaje działać
  1. $sql='SELECT * FROM events WHERE email = '.$row['email'].'';
  2. $result = mysqli_query($conn,$sql);
  3.  
  4. $mail->Body = '
  5.  
  6. <table style="text-align: center; width:100%" border="2" cellspacing="5" cellpadding="5" class="w3-table w3-striped">
  7. <tr>
  8. <th class="text-center">Imie</th>
  9. <th class="text-center">Nazwisko</th>
  10. <th class="text-center">Filia</th>
  11. <th class="text-center">Data</th>
  12. </tr>
  13.  
  14. while($row = mysqli_fetch_array($result)) {
  15. $name = $row['name'];
  16. $lastname = $row['lastname'];
  17. $service = $row['service'];
  18. $data = $row['start'];
  19.  
  20. <tr>
  21. <td>'.$name.'</td>
  22. <td>'.$lastname.'</td>
  23. <td>'.$service.'</td>
  24. <td>'.$data.'</td>
  25. </tr>
  26.  
  27.  
  28. }
  29.  
  30. </table>
  31.  
  32.  
  33.  
  34. ';
Go to the top of the page
+Quote Post
skleps
post 22.01.2020, 18:55:30
Post #2





Grupa: Zarejestrowani
Postów: 142
Pomógł: 9
Dołączył: 3.03.2011

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


Dlaczego kod umieszczony w zmiennej miałby się wykonać? Kod umieszczony w ciele zmiennej jako string pozostaje stringiem.

Proponuję coś takiego, dodatkowo możesz obsłużyć sytuację, gdy z bazy nic nie przyjdzie:

  1.  
  2. $sql='SELECT * FROM events WHERE email = '.$row['email'].'';
  3. $result = mysqli_query($conn,$sql);
  4.  
  5.  
  6. $allRows = '';
  7. while($row = mysqli_fetch_array($result)) {
  8. $allRows .= '<tr>
  9. <td>'.$row['name'].'</td>
  10. <td>'.$row['lastname'].'</td>
  11. <td>'.$row['service'].'</td>
  12. <td>'.$row['start'];.'</td>
  13. </tr>';
  14.  
  15. }
  16.  
  17.  
  18. $mail->Body = '
  19.  
  20. <table style="text-align: center; width:100%" border="2" cellspacing="5" cellpadding="5" class="w3-table w3-striped">
  21. <tr>
  22. <th class="text-center">Imie</th>
  23. <th class="text-center">Nazwisko</th>
  24. <th class="text-center">Filia</th>
  25. <th class="text-center">Data</th>
  26. </tr>'.$allRows.'</table>';
  27.  
  28.  
  29.  
  30.  
  31.  

Go to the top of the page
+Quote Post
extremist
post 23.01.2020, 12:29:47
Post #3





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 1.08.2019

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


Super, dziękuje za pomoc. Wszystko śmiga
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: 16.04.2024 - 05:07