mysql - 一条新闻可能会有多张图片,新闻和图片是间插着这显示的,这样的数据表该怎样设计?
ringa_lee
ringa_lee 2017-04-17 15:44:59
0
6
691

一条新闻可能会有多张图片,新闻和图片是间插着这显示的。这样的数据表该怎样设计?图片需要单独的一张表吗?

菜鸟求高手,详细一点。

ringa_lee
ringa_lee

ringa_lee

reply all(6)
Peter_Zhu

There is no need to create a separate table for pictures. You can use a rich text editor to edit news content, upload pictures, etc. The pictures are saved in the website directory, and the img in the html is linked to the corresponding picture file in this directory

巴扎黑

What is the interpolation method? Randomly inserted like an article? Or are there certain regular intervals? If it is like an article, you can use an editor like kindeitdor which is great

伊谢尔伦

HTML is designed in such a way that when visiting a website, only one HTML file will be returned. But what about images (img) in HTML? He will re-initiate a request.
So, just save the news directly in your data table. As for the picture, you save the picture locally (or in the database), and then use <img src="image address"> to replace the picture. When you get this news, look for <img> in it, get the picture, and then replace it in the news.

The above idea is applicable to all terminals. If you are developing a website, then the browser will help you solve the search and replace step.

左手右手慢动作

kindeditor or UE can be used, directly html

小葫芦

If the pictures in your article need to be used in other articles or other places (that is, when the image address in the site is allowed to be used), you should use a field to store all the image addresses in the article

黄舟

I think you should design an article table with the following fields

CREATE TABLE `article_xxx` (
  `id` INT(11) NOT NULL AUTO_INCREMENT ,
  `article_json` BLOB,
  `create_time` DATETIME,
  `update_time` DATETIME
  PRIMARY KEY (`id`),
);

Then as mentioned above, if your front-end is a rich text editor, don’t worry about the pictures. The pictures will have an address after they are uploaded to the website directory or cdn specified by your back-end. Then you only need to add this whole Type the thing into json and save it to the article_json above (of course I picked a random name here, you can choose it yourself). When displaying and calling in the future, just read out the json and display it directly.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template