I am creating a website like medium. As I am new in web development I am using php ajax with mysql database and storing posts of users in JSON format. Click to see database structure. Titles and descriptions are inside JSON. My questions are:-
Thanks for help :)
"can you" - yes. should you no.
You're going to need several related tables, at minimum articles
, comments
, users
and likely more as you'll want to store attachments in a different table as well. Generally JSON should not be used for data you wish to search/index. more store for convenience.
Example table structure. This is to get the "juices flowing" and "point you in the right direction", it should NOT be taken verbatim and turned into a production database.
If you use the below, if you want to search for articles that contain the word "cats" you simply use
SELECT * FROM articles WHERE content like '%cats%';
articles
column name | column type |
---|---|
id | int , autoincrement |
title | varchar(255) |
content | text |
created_by | int , Foreign Key users.id |
created_on | datetime , default now |
last_updated_by | int , Foreign Key users.id |
last_updated_on | datetime , default now, change on update |
comments
column name | column type |
---|---|
id | int , autoincrement |
article_id | int , Foreign Key articles.id |
content | text |
created_by | int , Foreign Key users.id |
created_on | datetime , default now |
last_updated_by | int , Foreign Key users.id |
last_updated_on | datetime , default now, change on update |
users
column name | column type |
---|---|
id | int , autoincrement |
name | varchar(255) |
username | varchar(255) |
text |
|
password | varchar(255) STORE HASHES NOT PLAINTEXT |
created_on | datetime , default now |