Populating matrix radio buttons from db - php

I'm currently working on a project where people can give theire feedback about the website, just like www.usabilla.com. But i'm stuck at designing my database.
I would like to make it possible for users to create matrix radio buttons with a label above them. Something like the second image on this page; https://www.webpoll.org/program/help/Help_QuestionType_GRB.php
Does anyone of you guys have an idea how I should design my tables, including the relationship, to make this happen?
Thanks in advance.

You can create a standard Product table with id, title, description, etc...
and another table called product_ratings with a product_id relationship, user_id (User relation) and 4 more columns as Quality, Efficiency, Price, etc... every of this columns will be an integer or NULL.

Related

(MySQL) How do I add an item id to all users?

I'm new on programming, sorry if I can't explain my doubt very well...
My friend have a online game and I help him to manage it. The php has a table for the users (meh_users), and a table for the items that the users have (meh_users_items). Each item has a id, (column itemid) and also the users (column userid), and in the table of the items that the users have, there is a id for the combination of the user and the item. (just id, and sorry, I don't understand this so much).
There is an image, if this make more easy to understand me:
phpMyAdmin printscreen
I want to add an item (let's think that it's a sword and this item have the id 3454) to all the users, but I don't want to delete the other items that the users have. Also I don't want to insert the data on the table one by one, because it's more than a hundred users.
Hope I have said enough details!
Remember: I'm new and I already search soooo much in the internet before asking here.
I suppose you want to give that sword to all users, including ones that already have it. You don't need PHP for this, SQL is enought.
INSERT INTO meh_users_items (userid, itemid, equipped)
SELECT userid, 3454, 0
FROM meh_users
This is just an example. You need to add all field to SQL.
Three steps:
If it isn't there already, add the new item (e.g., the Sword of Power) to your meh_items table.
Get a list of all your users from the meh_user table.
Write a foreach statement creating an entry in the meh_users_items table for each user.
It also occurs to me that your database might have some setup issues. E.g., meh_users_items has a column indicating item type (e.g., weapon). That could end up being problematic. Better to keep that information with the items in the meh_items table.

How to use dynamic field type in mysql?

I want to design a little on-line store. The website should have every detail about products. Since I am beginner I stuck at designing good database design.
There are many different products: Cellphone, Laptop, Stove, Bag, etc. Each of these products need different details. I am not going to design many different table for each, So one table (product) going to have all products.
But How I manage details? I couldn't find good topic on Google so I started my own poor design. This is my draft design:opps can not post image
Product stores product name.
Product_category defines type of product, like: mobile or book. each product belongs to one product category
Product_category_detail stores product attributes like color, wight,
battery life etc. each product_category_details belongs to one
product_category.
Product_detail keeps values of detail like 3 hour
for battery life, or 400g for wight. each of this belogns to one
product category detail and product.
I can store all details in Var-char.
Is it good? any suggestion!
It's better to have type of detail. like varchar for color and int for wight.
I am thinking on another field in product_catefory_datail named attr_type so I can change convert in php.
Any idea? tnx
I suggest you to use product table only to keep generic information about product, than have product_attributes table:
ID (INT|Unique) | product_id (INT) | name (VARCHAR) | value (VARCHAR) | type (INT: predefined constant values)
This is where you do need the Entity Attribute Value (EAV) model. If you need different data types then you need additional columns to specify the data type and for each data type: eg type specified as 'string' so select the string_value column, 'number' select the numeric_value column. That means CASE statemenst everywhere. Makes the whole thing horrible to work with.
an online store is very complex, and not really a beginners task. It wont be scalable and since you dont know yet how many variations you need you'll end up with adding new tables and columns until it gets too complex. Stores usually have a EAV model for this; http://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_model .
I had this similar issue while doing a project, and developed tables which solved my problem . Hope this helps you too.
product_table
pt_id,name,category
product_category_table
pct_id,name,desc
detail_fields
pf_id,field_name
product_detail_fields
pdf_id,pt_id,pf_id,default_value
product_detail_fields_values
pdfv_id,pdf_id,value,user_id //here pdf_id is fk of product_detail_fields
If you have multiple users, make use of user_id, else ignore it.

Need advice on fixing MySQL database design & table structure

I am planning to create a web application that using php-mysql, I created database to provide to store the form results. I create each column for each input fields in the database, It's working fine except that people tell that I'm doing it wrong because the database design that I created is "too static, bulky".
I created these columns: date, name, address, phone, bla bla, service1, service_price1, service2, service_price2, service3, service_price3, service4, service_price4, service5, service_price5, part1, part_price1, part2, part_price2, part3, part_price3.
I think my database columns is too bulky and static especially in the service and part. I'm looking for a better way to design my database and making it viewable in query results. Any advice for me? Thanks in advance
Here is my form sample:
Here is my database structure:
You should split this into multiple tables, one for customers, one for products (services), one for orderItems, and one for orders.
The orderItem table can hold reference to the customer and the list of products in this order, for example:
orderItemId_a : orderId_1 : customerId_a : productId_01
orderItemId_b : orderId_1 : customerId_a : productId_03
etc.

Fill list from different table based on primary id

I have 3 table which have relation with each others... In 1st table, i have student details contains studentid (PK), studentname, dob, etc...
Table 2 contain course consist of coursecodeid(PK), studentid(FK), coursename, teachername and etc..
Table 3 contain grade consist of studentid(fk), courseid(fk), id(pk_autoincrement) and grade.
When system starts, studentid will be load into a dropmenu. Onchange this dropmenu, second dropmenu will be shown and load with courseid take by selected student (based on studentid)
When user select courseid onchange a label will be visible to show student grade.
Everything done in 1 page... Anybody can give me sample code either in php or javascript since i am using php and mysql database.
Ajax. That is the way to go. Check here for ideas, this is doing something similar to what you are trying to achieve. Check this for more abstract code reference. This is a possible duplicate. And generally, searching for loading combobox based on other combobox jquery will give you pretty decent results.

The right database structure and model relations in CakePHP for my project (small shop)?

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.

Categories