I need to make a news feed is about this design but it is not mine

{ "status": "OK", "data": [ { "id": "103", "title": "sdvdgddgasdfgd", "body": "dfgsdflgdsfgdsf", "created": 1501483394, "author": { "name": "Caria Estates", "logo": "http:\/\images\/logos\/cariaestates.png" }, "image1": "http:\/\/img\/social\/luxury_apartments_with_sea_view_for_sale_in_alanya_2.jpg", "image2": "http:\/\/img\/social\/luxury_beach_front_property_for_sale_in_alanya_11.jpg", "likes": 19 }]} 

I manage to bring it out on my page and everything is fine, the question is how to create such a construction that it is better to use and where it is best to store all the information, for example in a database (MySQL) or just create ARRAY via JSON and store it all there

    2 answers 2

    I prefer to use database (MySQL).

    We create news table (id, title, body, created, author_id, likes) in it we store news.

    Data about authors is stored in the author table (id, name, logo)

    Data about pictures news stored in the table news_image (id, news_id, save_path)

    And in the output we are requesting data from the news table and from related entries in the author and news_image tables.

    We form an array of data and json_encode output from it.

    • But why form in JSON if I can and so withdraw I apologize for the stupid question I just can’t understand the meaning and one more question with the body part what is the value set in the varchar type database (10000000000) ???? - Sergey
    • body - text, it is up to 64 kb, you can mediumtext if it is missing. If your news is always the same, then make ready-made JSON. If news is added, and you need to make the admin panel, with the addition of pictures, their processing, checking access rights, etc. - the one here is PHP + MySQL - Ivan Bolnikh
    • that is, if my news works on the same principle as the logo, name, post creation time, one or two pictures, is it better to make a template from JSON and store everything there? or can i just use Sql? or is it wrong and maybe slow? In terms of download - Sergey
    • one
      JSON is a manual entry and potential input errors that may result in the news page not being displayed. But it is fast, if there is little news. So it’s rather a matter of convenience, how much time you have to develop and how much skills. - Ivan Bolnikh

    For these purposes, they use the database, and JSON files, and simply generated html cache pages. The latter is used in conjunction with a database. It makes no sense to pull up the content every time you access the page, if it is not interactive, but static. They use a template engine that will cache the output, thereby reducing the load on the database and the site as a whole.

    • But can you please like something more detailed and preferably with some kind of code or with links - Sergey
    • it is enough to search for articles on the topic of php template engine. But again, it all depends on the load on the site. If there will be several views per day, then you can safely remove everything from the database as it is. But if the load is high enough, plus there are comment modules that will also load the same database, you need to think about output caching. - Denis
    • Well, until the expected load of 100-200 people per day - Sergey
    • you can not worry, leave everything as it is, there is no need just complicate the project. However, you can read about the types of caching habrahabr.ru/company/zerotech/blog/316316 - Denis