简体   繁体   中英

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:

ad_title ad_price ad_body
car 10028 2015, 999km, 4+
book 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']);

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 attribute
59 Mileage

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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