Efficient mysql db structure advice
I'm developing a site that will be a subscription based service that will
provide users several courses (videos) based on whatever they signed up
for.
Currently I was considering the following db structure
Users
------
email | pwd | subscription_date | expiration_date
Unique Key would be "email"
Course_Subscription
-------
email | calculus_1 | calculus_2 | physics_1 | physics_2 ... | Nth course
the number of courses offered will probably start at approx 15, and
gradually increase overtime. Also the course subscriptions will be boolean
value of TRUE/FALSE
then a table for each course as follows:
Calculus_1
----------
id | title | description | video_url |
there could be more than 20 chapters in a single course.
A little bit of info on authentication process - it will go userlogin --->
course subscription ---> course chapters. Where both user login and course
subscription will be verified against the email address. The videos will
also be checked against the subscription table prior to being played.
My questions are:
Is this the best way to structure this? Or are there better alternatives?
Would this cause any problems in terms of performance? Or would it not be
noticeable?
Here is a sample of a php script that I'll use to authenticate and
populate the html
$sqlSubscription = "SELECT * FROM course_subscription WHERE `user` = $user
&& `calculus_1` = TRUE";
$subscriptionResult = mysql_query($sql) or mysql_die($sqlSubscription);
while ($row = mysql_fetch_assoc($subscriptionResult))
{
$user=$row["email"];
$calculus_1 =$row["calculus_1"];
if($user==1 && calculus_1==TRUE)
{
$sql = "SELECT * FROM calculus_1 ORDER BY `id`";
$result = mysql_query($sql) or mysql_die($sql);
if (mysql_num_rows($result) > 0)
{
$data = array();
while ($row = mysql_fetch_assoc($result))
{
$data[] = $rows;
echo "HTML THAT WILL CREATE A LIST BASED ON TABLE INFO"
}
}
}
}
The above code is for the menu that will populate a list of chapters based
on their subscription. I know the code isn't perfect, I'm still working on
it - but I wanted to nail down the structure of the db first now that I
have a fairly decent idea of how I'll be accessing the information.
No comments:
Post a Comment