As I'm learning PHP I'm making a personal episode tracker for tv shows. My issue right now, is that I don't know how to print out a "pretty list" separated by season. Right now every single episode of a series is printed with a loop from the mysql query. There's also a "watched" function in here that I need to use to check if a user has marked the episode in the loop.
How can I loop one season at a time instead of every single episode? I got the amount of seasons as and int in another "Series" table if that makes it any easyer.
// Get episodes from database
$list_sql = "SELECT * FROM episodes WHERE series_id = '".$_GET['id']."' ORDER BY `episodes`.`season` ASC, `episodes`.`season_episode` ASC LIMIT 2000";
$list_query = mysqli_query($con, $list_sql) or die(mysqli_errno($con));
while ($row = mysqli_fetch_assoc($list_query)) {
// GET INFO ON WHEN EPISODE WAS VIEWED
$when_watched_sql = "SELECT date_watched FROM watched WHERE episode_id = '".$row['id']."'";
$when_watched_query = mysqli_query($con, $when_watched_sql);
$when_watched_result = mysqli_fetch_assoc($when_watched_query);
// IS EPISODE WATCHED? If yes, make CHECKBOX CHECKED
$watched_sql = "SELECT watched FROM watched WHERE episode_id = '".$row['id']."' AND watched = '1'";
$watched = mysqli_query($con, $watched_sql);
if(mysqli_num_rows($watched)>0) {
// One row returned, episode is watched
$watched_box = "checked";
} else {
// No rows returned, episode is not watched
$watched_box = "";
}
print("Watched: <input type='checkbox' name='watched[]' value='".$row['id']."' $watched_box /> Season: ".$row['season']." Episode: ".$row['season_episode']." ".$row['name']." <br>");
}
I probably have quite a few wrong ways of doing things here too, I do enjoy some constructive hints and tips for learning how to do this all in a proper way.