I am working on an E-learning application and by far I have completed many things from a simple admin to teacher chat system to a virtual live classroom in PHP and MySQL.
Now came the most difficult part course creation and management operations with courses. You might be thinking that doing that in MySQL ain't hard and yes It is not difficult but the part where my logic stops working is the relations between tables like e.g. the relation of the course table and the lessons table used for the lessons inside the courses.
My question is that is there a way to relate both of the tables or should I create a separate database for the courses part of this project or something like that.
At this point I don't need any help in the code I need help in the logic used for relating these tables if possible.
This is my courses table below:
-- phpMyAdmin SQL Dump
-- version 4.9.2
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1:3306
-- Generation Time: May 22, 2020 at 06:11 AM
-- Server version: 10.4.10-MariaDB
-- PHP Version: 7.3.12
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `e-learning remake`
--
-- --------------------------------------------------------
--
-- Table structure for table `courses`
--
DROP TABLE IF EXISTS `courses`;
CREATE TABLE IF NOT EXISTS `courses` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`courseAuthor` varchar(1000) NOT NULL,
`courseName` varchar(255) NOT NULL,
`courseDesc` varchar(255) NOT NULL,
`courseTags` varchar(1000) NOT NULL,
`courseImg` varchar(255) NOT NULL,
`isApproved` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=18 DEFAULT CHARSET=latin1;
This is my lesson table below:
-- phpMyAdmin SQL Dump
-- version 4.9.2
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1:3306
-- Generation Time: May 22, 2020 at 06:14 AM
-- Server version: 10.4.10-MariaDB
-- PHP Version: 7.3.12
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `e-learning remake`
--
-- --------------------------------------------------------
--
-- Table structure for table `lesson`
--
DROP TABLE IF EXISTS `lesson`;
CREATE TABLE IF NOT EXISTS `lesson` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`LessonName` varchar(255) NOT NULL,
`LessonContent` varchar(255) NOT NULL,
`CourseOfTheLesson` varchar(255) NOT NULL,
`LessonPostDate` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
COMMIT;
The thing is that I want to know how to relate them so that If a student clicks on a course he/she will be redirected to the first lesson of that particular course and then so on.