Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

successdav's avatar

CONFUSE ON HOW TO SET THIS TABLES UP, I NEED HELP

I am building a web app for a school and I need to arrange the topics into sections.

I have a course model and I want to arrange the course content into sections, e.g. COURSE TITLE - LEARNING PHP

  1. Getting Started with PHP
    • What is php
    • writing your first php syntax
  2. PHP and MYSQL
    • making a connection to db
    • listening for response

this is what I came up with

CREATE TABLE courses (
  course_id INT NOT NULL,
  title VARCHAR(50) NOT NULL,
  PRIMARY KEY(course_id)
);


CREATE TABLE sections (
  section_id INT NOT NULL,
  title VARCHAR(50) NOT NULL,
  course_id INT NOT NULL,
  PRIMARY KEY(section_id),
  FOREIGN KEY (course_id) REFERENCES COURSES(course_id)
);



CREATE TABLE topics (
  topic_id INT NOT NULL,
  section_id INT NOT NULL,
  title VARCHAR(50) NOT NULL,
  video_url varchar(255),
  PRIMARY KEY(section_id),
  FOREIGN KEY (section_id) REFERENCES SECTIONS(section_id)
);

but my problem here is when i collect all sections related to a course, it is sorts the sections according to timestamp and I cant sort by title either because 1 can be zzzz and section 2 aaa.

please how do I go about this. if my schema is not appropriate, please guide me thanks

0 likes
5 replies
Snapey's avatar

sections and topics both need some form of sequence number which you set when creating them. This could be a simple integer column.

How you enter it is up to you and depends how good your front end skills are. At its simplest, just a form field in which you enter the sequence number.

successdav's avatar

Thanks alot @ Snapey... You are awesome.... just b4 I go try this out...

Will this not create a problem when creating a new record? like having to determine what is the last sequence number in the module so I can increment it. like wise update a record, imagine someone wanting to reorder the the sequence (may wants number 2 to become number 5)... I then will have to reorder the whole sequence column.

It will help me alot if you can brief me on this two crude operation (create & update) based on your solution.

Snapey's avatar
Snapey
Best Answer
Level 122

it depends how you are collecting these elements

You could present all sections in the order they were created by setting the initial order to zero and then having the id as a second sort condition.

Then present the user with a page that allows sections to be reordered. This could be a draggable ui or a simple form with a sequence number field. The form can be filled with a number representing the current order, then when the form is posted, write the new values to the sections.

Please or to participate in this conversation.