How to disassemble and send the array in a table using mail()?

Good day!
There is a need to pull from the database information and send the table by e-mail.
To send mail I know how to operate with data from dB too, but I don't know how can I make a table in a message that went a table with all selected rows. Tried to do a cycle, but nothing comes out.
$subject = "Subject";

require_once('db.php');

function get_s()
{
 global $link;
$link->set_charset("utf8");
 $p1 = 'xxx';
 $sql = "SELECT * FROM current WHERE par= '$p1' ORDER BY id";
 $result = mysqli_query($link, $sql);
 $ps = mysqli_fetch_all($result, MYSQLI_ASSOC);
 return $ps;
}
$message = '<table>
<thead>
the <tr>
 <th scope="col">col1</th>
 <th scope="col">col2</th>
 <th scope="col">col3</th>
 <th scope="col">col4</th>
</tr>
</thead>
<tbody>
the <tr>
<th></th>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>';
$headers= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
mail($to, $subject, $message, $headers);
April 19th 20 at 12:21
1 answer
April 19th 20 at 12:23
Solution
// $data = get_s();
//
<tbody>
the <tr>
 <td>' . $data['key'] . '</td>
 there are other fields
 </tbody>
Most likely will have to add another loop on 4 fields td - laura.Price23 commented on April 19th 20 at 12:26
@laura.Price23, yeah, that actually was the question - how to correctly add a loop in such a structure.
I tried to do the same, but yet don't understand how to do the loop in this case.
$message = '<table>
<thead>
the <tr>
<th scope="col">col1</th>
<th scope="col">col2</th>
<th scope="col">col3</th>
<th scope="col">col4</th>
</tr>
</thead>
<tbody>'
. foreach ($data as $ps): .
'<tr>
<th>' . $ps['item_1'] . '</th>
<td>' . $ps['item_2'] . '</td>
<td>' . $ps['item_3'] . '</td>
<td>' . $ps['item_3'] . '</td>
</tr>'
. endforeach; .
'</tbody>
</table>';
- Colt2 commented on April 19th 20 at 12:29
@Colt2, well, do so
$message = "; // here is the header of the table
foreach(get_s() as $data) {
$message .= '<td>' . $data['key'] . '</td>' .
// other fields
}
$message .= "; // table leg

.= this adds to a variable - laura.Price23 commented on April 19th 20 at 12:32
@laura.Price23, thank you so much for the clarification, you're great! - Colt2 commented on April 19th 20 at 12:35

Find more questions by tags PHP