i've got a database with the folowing info:
--------------
id | Book | Names
1 | 1 | Tom
2 | 8 | James
3 | 10 | Tom
4 | 2 | Tom
5 | 17 | James
6 | 2 | James
7 | 9 | James
8 | 7 | Tom
9 | 8 | Tom
This table shows books read by "Tom" and "James".
These are the requirements i need:
to show the next book not read. (eg. Tom's would be '3' and James's '1')
to skip book '1', '10' and '15' as these are no longer available. (so in James's case, the next book would be '3')
if it cannot be sequential, any random book not read will do as well.
here's what i did:
$sql = "Select * FROM books Group By names";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$sql1 = "SELECT * FROM books WHERE names = '" . $row["names"]. "' ORDER BY book ASC";
$result1 = $conn->query($sql1);
if ($result1->num_rows > 0) {
$newbook = '1';
// output data of each row
while($row1 = $result1->fetch_assoc()) {
if ($row1["book"] == $newbook) {
echo "Exist<br><br>";
$newbook = $newbook+ 1;
} else {
if ($row1["book"] == '1' || $row1["book"] == '10' || $row1["book"] == '17') {
$newbook= $newbook+ 1;
} else {
echo "Add".$newbook."<br><br>";
break;
}
}
}
}
}
}
This is how far i've got. All help appreciated. Thanks