I have some records, which I use while($row = $result->fetch_assoc()
to iterate on each one of them, then I get some other data from a different table using while($row2 = $result2->fetch_assoc()
, that is, iterating also on each one of them, then displaying in a HTML table: part of first table data and part of second table data.
However, when I truncate the first table, and then insert new records, the second query $result2->fetch_assoc()
, starts from the beginning of table and iterates X times, which is basically numbers of rows from first table. This is not what I want, I want to remember the last place of iteration from its table (table 2), then, when called again, only iterate the remain rows in the second table, always which is dependent on nth times from first table.
I found an answer in stackoverflow, which you can find it here, however, I didn't understand it correctly: how can you save last LIMIT value, so to start from X id if the $result2->fetch_assoc()
is called again?
I thought about storing a counter in a text document (which is incremented by first while loop), then use LIMIT
from that certain number, but I don't really get how to get it work.
Edit: here are some additional info:
Table "aplikimet" schema:
Table "aplikimet_2" schema:
$sql = "SELECT id, emri, mbiemri, email, telefoni, vendbanimi, datelindja, mesazhi FROM aplikimet";
$sql2 = "SELECT statusi, uid FROM aplikimet_2";
$result = $conn->query($sql);
$result2 = $conn->query($sql2);
if (($result->num_rows > 0) AND ($result2->num_rows>0)){
(html table and th are here)
while((($row = $result->fetch_assoc()) AND $row2 = $result2->fetch_assoc()){
(html td are here)
Thanks for your help!