A
A
Albert Tobacco2014-06-29 19:20:58
PHP
Albert Tobacco, 2014-06-29 19:20:58

How to organize a database for a blog?

I intend to write a travel blog. That is, people come, register, post their photos and text, and share it with other people. At the very beginning there was a question how to organize a DB?
I'm going to make it so that the article would be broken down by day, that is, a person will add a day - shove photos and text there, then add day number 2, etc. And only then sends all the forms that I enter into the database.
So far, I have an option in my head - for each article - to make a new table, but I don’t know, is that how they do it?
But here I also have a question. There can be 30 photos for one day, or maybe 0. There is an option to attach photos to the text, or vice versa, but I don’t know how it will be more literate. This is why I can't get started.
I will say right away that this is my first site, I will use mySQL + PHP.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexander N++, 2014-06-29
@sanchezzzhak

Under each article, a new table is nonsense, you should not repeat this path.
I had a project, not even one, but 10+, on support there, for each entry, a plate was created with 1 entry.
Everything worked well, but mysqadmin just died, such a database could not be transferred to another hosting mysqldump just hung during the dump. the approximate number of tables was 3.2k-4k.
Create a table for articles for articles, for example posts
id int(11)
user_id int(11)
datecreated timestamp
dateupdated timestamp
content text
title varchar(255)
h1 varchar(255)
For photos photos
id int(11)
post_id int(11) is a link to post_id
path path to the photo, for example /storage/photo/a1/d1/d2/(md5).jpg desctiption varchar (
255)
datecreated timestamp
dateupdated timestamp md5).jpg 250x250_(md5).jpg Download laravel framework or Yii1-2 and create migrations based on 2 schemas above. We use the framework's internal generator to create models. We create the necessary controllers and write the code. You can do it without OOP, but it will take a long time. You can put worpress and add a couple of plugins to expand posts, such as ACF, but it has a paid gallery and the rest of the fields are free.

V
Vadim, 2014-06-29
@vshemarov

Everything shows that you have too little knowledge and experience to create such a resource from scratch.
Just think:
For each user you need to create an account, authorization system, password recovery, etc.;
It is necessary to differentiate access rights for each user - who can do what with his blog, and what with someone else's;
When uploading images, it is necessary to provide for loading both from a computer and from third-party resources, resizing and fitting to certain sizes, control over the type of uploaded file, convenient viewing of photos, etc., etc.;
Not only creating, but also editing and deleting both log posts and photos;
Administration of all this goodness (you never know who will start uploading what);
...
And many, many more all sorts of nuances to take into account, the description of which will be more than one page.
Or you can take a ready-made engine and, without any magic, get what you need on a turn-key basis: users register, each receives a personal blog during registration, they can post stories and photos there, other users can comment on them, like them, repost them on all sorts of Facebook and VKontakte, and you focus not on solving a lot of tasks, small and large, that have already been solved before you, but on the development of the project

I
IkaR49, 2014-06-29
@IkaR49

And even if they don't, it doesn't matter, try. It will be good - leave it like that, it will be bad - do it differently. This is the first project, this is the most interesting, this is the best thing to learn!
As an option, to attach photos: make a kind of wiki markup. That is, to insert a photo, a code is written and the number of the photo from the uploaded ones is indicated. Here, there will be a plus, all of a sudden someone does not want to upload photos to you, but adds them to an external hosting. Then you just need to store the plain text and upload it on request.

A
Albert Tobacco, 2014-06-29
@bighoc

I want to write without using frameworks and wordpress, because I didn’t work with either one or the other. And now there is no such goal, just PHP and mySQL. But here's one thing that's muddy for me, how does the database store the photo? Should there be a field for it too? In the sanchezzzhak example, I did not find it. But I like this option with two tables.
datecreated timestamp
dateupdated timestamp
These two fields, as I understand it, are a timestamp, but if the photo was uploaded, how can it be updated?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question