0

Im doing a project for my collage (e-learning website with php back-end and bootstrap front-end, something like moodle). I have already created login/register system, add/edit users/courses systems etc. But i've got stuck on displaying only those courses that given user has access to.

courses table users table I was trying to achive this by adding multiple user logins to column in every course (course_students) but first i dont know how to do this and 2nd it feels wrong and complicated , any idea how i can validate that ? Im currently using procedural php, this doesnt have to be super secured and efficient

function coursesMainlist() {
include "connect.php";
if ($result = mysqli_query($conn, "SELECT course_id,course_name,course_catagory FROM courses WHERE course_students = {$_SESSION["userid"]}")) {
    while ($row = mysqli_fetch_row($result)) {

        echo "                            <a class='list-group-item list-group-item-action text-muted'  href='lekcja.php'>
                            <div class='row'>
                                <div class='col col-md-6'><span>{$row[2]}<br><span class='text-dark'>{$row[1]}<br></span></span></div>
                            </div>
                        </a>";

    }
    mysqli_free_result($result);
}

mysqli_close($conn);

}

php code

App1e
  • 1
  • 1
  • As per [ask] you must not post pictures of your code. Code is text, please edit it into the question as text – ADyson Mar 16 '22 at 17:03
  • 1
    But anyway the concept you're looking for here is a "many to many relationship" in your sql database, which is represented by a 3rd table which sits between courses and users (conceptually i mean), containing columns user ID and course ID. That way you can record one user belonging to many courses and many courses being associated with one user, very easily, without denormalising your data – ADyson Mar 16 '22 at 17:06

0 Answers0