简体   繁体   English

数据库架构 [用户帖子]

[英]Database Schema [User Posts]

So the site I build has different types of posts and when users post the form is based on which category they selected if they select cars it will ask built year, mileage, doors, if they click books it will ask the author, book damage, etc...所以我建立的网站有不同类型的帖子,当用户发布表单时,他们会根据他们选择的类别选择汽车,如果他们选择汽车,它会询问制造年份、里程、门,如果他们点击书籍,它会询问作者,书籍损坏,等等...

Now when it comes to the database schema I tried to think how I can save the different fields because I don't want to make a column that's called mileage and it will be empty when the user selects books because I think that is a bad design so I made it like this:现在,当谈到数据库模式时,我试图思考如何保存不同的字段,因为我不想创建一个名为 mileage 的列,当用户选择书籍时它将为空,因为我认为这是一个糟糕的设计所以我是这样制作的:

ad_title广告标题 ad_price广告价格 ad_body广告正文
car 10028 10028 2015, 999km, 4+ 2015, 999km, 4+
book 212 212 James, no damage詹姆斯,没有伤害

As you can see I save the fields that chanage based on the category as $ad_body $ad_body = implode(',', $_POST['body']);如您所见,我将根据类别更改的字段保存为$ad_body $ad_body = implode(',', $_POST['body']);

then when I want to display it I just say然后当我想显示它时我就说

$ad_body = explode(',',get_post($id);,'ad_body'));
echo $ad_body['1'];

this seems like an okay way of doing it but now I ran into the problem when I built the search page I change the search form based on which category the same rules apply but how do I search for mileage or book author etc.. because they are in the single-column which tells me my database schema is build poorly and I need help on how I can change it to still be able to save different types of posts while being able to search for those specific values.这似乎是一种不错的方法,但是现在我在构建搜索页面时遇到了问题我根据适用相同规则的类别更改了搜索表单但是我如何搜索里程或书籍作者等..因为它们位于单列中,它告诉我我的数据库架构构建不佳,我需要有关如何更改它的帮助,以便在能够搜索这些特定值的同时仍然能够保存不同类型的帖子。

Okay, I found a solid-looking solution for my problem.好的,我为我的问题找到了一个可靠的解决方案。 If anyone has a better DB schema please share and I appreciate your work.如果有人有更好的数据库架构,请分享,我感谢您的工作。 Thanks for helping me solve my problem.谢谢你帮我解决我的问题。

Post attribute帖子属性

post_id post_id attribute属性
59 59 Mileage里程

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM