So I have this MySQL query which is basically just two single while
loops running and displaying info as they should, the issue with this is they display information like:
Test1, Test2, Test1, Test2, Test1, Test2, Test3, Test4, Test3, Test4, etc...
As you would expect. Although what I am looking to do is arrange these results based on the dates they were added to the table, so if one set of test 3 and test 4
were added most recently, it would show as:
test3, test4, test1, test2, test1, test2, test3, test4 etc...
So kind of rearranging these results based on the dates? I know using ORDER BY
would only show each section in order but is there a way using my code which I can mix them ALL up and rearrange by both date_added
and date_earned
?
$user_id = $_SESSION['userid'];
$sql8 = "SELECT * FROM table1 ORDER BY date_added;";
if ($result8 = $conn->query($sql8)) {
/* fetch associative array */
while ($row8 = $result8->fetch_assoc()) {
printf ("%s (%s)
", $row8["test1"], $row8["test2"]);
}
}
$user_id = $_SESSION['userid'];
$sql9 = "SELECT * FROM table2 ORDER BY date_earned";
if ($result9 = $conn->query($sql9)) {
/* fetch associative array */
while ($row9 = $result9->fetch_assoc()) {
printf ("%s (%s)
", $row9["test3"], $row9["test4"]);
}
}