I'm creating a website using Symfony2 and I want my users to see a list of items according to their profile. I am looking for the best way to do that.
The users have basic fields attached to their profile (first name, email, etc.) but I want to add some specific information: gender, income, interests (so different types : bool, integer, string etc). Some fields and values may be added, modified or deleted later.
The items will have criteria so that they will be shown to the corresponding users according to the users' profile.
Actually it is a bit like a shopping website with information attached to products and then the client can reduce the number of items shown thanks to a list of criteria.
I thought of putting an array with the different criteria and values in the User entity but I find this solution really bad.
Do you have an idea of what might be the best Entity/DB schema to do that?
This is filtering, your query which you use to get your product is the one you should play with not the user.
As i understood you want to show different product to each user depending on their gender etc..
You will need some kind of link to know which product to show to which user? Which information you want to check in the product side? you can have an entity linked to product with different information like gender male for a product that you will use in your query to get all select * from product where product.criteria.gender = user.gender this is just a simplified query but it is a bit more tricky with a join if you want to do it in SQL or DQL
Related
I have a shopping website and I allow users to list products. When they add a new listing, they must enter values from select box into main_category,sub_category and leaf_category fields in products_tbl.These fields are indexed because they make queries fast when viewing products. There is also is_reviewed flag in products_tbl which is 0 by default.
In my admin dashboard I get all listings that are not reviewed and check if they are in the right category. Almost all the time customers make mistake when they list so I edit the listing and update the indexed main_category,sub_category and leaf_category fields and change is_reviewed flag to 1. This means I have to update every time users list in wrong category and Its really becoming slow.
so what is the best way to do this? I have thought about creating another table and new listings stay there. so after reviewing I add them to to the products_tbl with correct categories. But I am not sure if this a good solution. I appreciate your help in advance
I am trying to create a database for storing cars information.
Cars can be categorized as new, used, or for rent.
Each type of car category has different attributes, because new cars have different features that are not needed for used, and same case for used and rent category. Attributes can be added, deleted in future using Application Admin side form manager for these 3 categories.
currently i am storing these in 1 product table with all the attributes required by these 3 categories.
PRODUCT(id,title,description,model,kilometer,enginsize,conditions,.....,.,...)
As form for each category is proposed to be managed from admin control, i am looking for a new scalable database.
current development:
all common attributes in Products
PRODUCT(pid,title,description,...)
CATEGORY(cid,cname) new,used,rent
form_field(formfield_id,name,type) to store all attributes that are not common
form_field_category(formfield_id,cid) to store category associated attributes
form_post_data(post_id,pid,formfield_id,value) to store submitted data
Any suggestions.
for what I understand you have 2 type of attributes: common and category-specific.
So doing something like:
PRODUCT(pid,title,description,...)
CATEGORY(cid,cname) new,used,rent
additional_info_category(aid, cid, name)
adition_info_data (adataid, aid, pid, data)
Should be enough, you just need to loead all the product info plus the fields in additional info that are related to the category.
You should have no issues adding new fields if they are category-specific but my question is: are you sure you won't need to add common fields?
What you need is called an Entity-Attribute-Value model.
If most of the values in table form_post_data are text, simply make it a varchar field. However if you're storing numeric values, choices and other types (things you might want to filter on), have a look at this article An alternative way of EAV modelling.
For you have properties that can have multiple values, have a look at this follow up article EAV multi-value fields.
I am currently working on a system that would allow users to add additional custom fields for the contacts that they add.
I wondered what is the best and most efficient approach to add such ability?
Right now what I was thinking was to have 1 table per users (with foreign keys to a "main" contacts table) and then adding a column for each custom fields that the user adds (since I don't expect to have more then 100-200 users per database shards [sharding is easy since every users never see each-other's content in this system]), although I am not 100% sure that this would be the right solution for such problems.
Maybe you could try to have one separated table to store a reference to the user, plus the field name and value, this way you will be able to have lots of custom fields.
If you go with Boyce-Codd, you separate the information and store them into a table.
Means one table for all users with a foreign key.
One table per user would lead to hundreds or more tables with possible repeated information.
You need to have one table named USERS that stores the id of a user and fixed info you might want. Then, you could have a CONTACT table, that stores the type of contact user might create, and one matching table USER_CONTACT that matches the user unique id with the id of the contact that was created.
With this, you could have advanced data mining on all the information stored, like nowing how many contacts each user created, who created more, etc...
I have a pretty simple shop-system. I'm working with CakePHP. Actually I wouldn't call it shop, it's rather a basic form where you can type in your data and which items in which color you want and that's it.
There is one buying-form which is "open to the public" and then there are buying-forms which are password secured.
The latter ones have a selection of the items (or selection of colors) which you get on the public site, but have discounts.
I want to save the orders in a database. I have a table orders and ordered_products. That's working fine.
It works pretty good, but only because I made something not very good: Since there are just a few products I just wrote an array in the controller with the names, prices and stuff... the discounts or selection of products I handled by just overwriting the products-property.
Well, putting data in the controller is not really the idea behind the MVC-Structure, so I was thinking about who to handle the products, the selection of products for the different password-secured buying forms and the discounts with models.
My idea was, to create the following tables:
products (id, name, price,...) -hasAndBelongsToMany Color
colors (id, name)
products_colors (product_id, color_id)
Now to set in which "closed-area", which products in which color and with which special price can be ordered I thought of the following tables (the actual table and field names are of course not wise chosen, but just for the idea):
product_selections (id, closed-area_name, product_id, special_price) hasAndBelongsToMany Color
product_selections_colors (product_selection_id, color_id)
When I'm creating the public buying form I would just use the top three tables. but building the "closed-area" I would use the bottom two, selecting the product_ids and special_prices from product_selection as well as the different colors over the product_selections_colors-table for the according "closed-area" (i dont know a better name for that right now...). with the product_id i would get the other information about the product from the table products and create the buying form with this data.
I want to have it all in a database, because then I can better work with the orders (creating receipts, deliverynotes etc.).
I would like to know what you think about that, because I have the feeling that I'm going totally in the wrong direction, since it feel way to complicated for such a simple thing...
I hope you can help me.
Based on your description, I would recommend doing it this way:
Have a users table with a field for "group_id". This allows you to have multiple users with login privileges that all can view the same options or colors based on their grouping.
In the case of a general (non-logged in) user, the assign the group_id to default to 0.
Next, ditch the product_selections and product_selections_colors tables.
You don't want to have to repeat products across tables.
Simply add a new table that pairs which product ids can be purchased by which group_ids. (HABTM relationship in cake)
You will obviously need to tweak this general setup to work specifically for your needs.
I have set up a company intranet website built with PHP/MySQL and allow users to post reviews. After joining up on this website I have grown to like the "comment" function and would like to add that same functionality to allow users to "comment" directly to other users reviews.
Currently all reviews are stored in a single table in the DB.
1) Should I create another table to then store all the comments since there can be many comments per review?
2) Once I figure out where to store these values can the rest of this functionality be built out in PHP or will other programming need to also be introduced?
Sounds like a good plan. You can have a table like Comments(commentID, reviewID, comment_body, ...). You can then insert a new entry when adding a new comment, or select all comments with a given reviewID to display comments for a given review.
Yes, you will almost certainly implement this in PHP (the same language you use in the rest of your application). You'll also have to edit some HTML, and maybe javascript as well.
Yes and yes.
Comments should be a seperate table, because they're comments, not reviews. They are two different things, therefore, they should not go in the same table.
Once you've created that table with the appropriate references to other tables, it's just a matter of constructing a query which pulls out all of the information you need (e.g. SELECT user.user_name, comment.comment_text, comment.post_time FROM comment, user WHERE comment.user_id=user.user_id AND comment.review_id = 123, where 123 is the ID of the review you're getting comments for).
The exact layout for your comment table will depend on your specific needs, but as a minimum, you'll want to know which review it's a comment for, who posted it, when they posted it, and what they actually posted.
To insert comments, create a form on the page that displays the individual review, and when filled in, create an INSERT query which inserts into your comment table.