I'm looping through 2 tables in MySQL DB (using fetch_assoc()). I would like to get the current id of the 1st table and all the ids of the second table on each iteration but I get the ids of the second table only on the first iteration. From the second iteration upwards, only the current id of the 1st table is returned. I would like to know what I'm doing wrong.
I've already tried for Loops and looked up similar questions here but none have really been of help.
<?php
$my_sqli = new mysqli('localhost', 'root', '', 'taskpro') or die(mysqli_error($my_sqli));
$data1 = $my_sqli->query("SELECT * FROM task_table") or die($my_sqli->error);
$data2 = $my_sqli->query("SELECT * FROM taskinfo") or die($my_sqli->error);
while ($row = $data1->fetch_assoc()) {
echo "<br>";
echo $row['id'];
echo "<br>";
while ($row2 = $data2->fetch_assoc()) {
echo $row2['id'];
} // end child loop
} // end parent loop
?>
This is the result I get
1
1234
2
3
4
5
6
7
8
9
10