I stucked in a Problem When Playing with Drop Downs.I tried to use this
http://www.grocerycrud.com/forums/topic/1087-updated-24112012-dependent-dropdown-library/
But actually my requirement is quite different. I have a table fwld_products in which i am adding all other table's categories, from
fwld_cat_main (main Category's ID),
fwld_cat_sub1 (sub1 Category's id)
fwld_cat_sub2 (sub2 Category's id)
fwld_cat_sub3 (sub3 Category's id)
I want to Display Dropdown in such a way, when user Selects main
Category, the Drop Down Appear (sub1) Having Data related to main
category and when sub1 selected drop down appear (sub2) showing data
related to sub1, and sub2 selected and drop down appear(sub3) to show
data related to Drop down (sub2).
When submitted Finnally data inserted to [fwld_products].
Here I am attaching ERD, and result as well.
Please help
Hold on, it seems that DB structure of your categories table needs to be improved. What I suggest is that you follow footprints from some of the popular CMS like Opencart. It will give you a great sense to accomplish your task. You can easily optimize your DB by using just one "category" table (instead of main, sub1, sub2, and sub3 category tables) like this:
For category names, description, and meta keywords etc you can create this table "category_description":
Finally to assign categories to the products you can simply create another table "product_to_category":
In this way you can easily manage your data in DB and you can now easily tackle your situation using Codeigniter and Grocerycrud.
Try, Chained Selects Plugin for jQuery and Zepto (Github Project | Project Home)
If you use jquery or zepto in your project, this plugin will help you to solve your problem, Specially the remote version. You can create related select boxes easily.
Hope this helps :)
Related
I have one Category List user will select a category from the list if user didn't find a category in the list, then he will select "other" option and it will display a text box there user will enter a new category name. This newly added category will go for approval to Site Admin till then it should be mentioned as "Uncategorised".
So my question is how to achieve this using a mysql table should I create a new table as uncategorized category or should I add one extra column to category table as "isApproved". As the solution should be for both add and edit of new category.
As you described
Admin must approve newly added category.
To acheive that you definitely will have a field status or something like that to check if this category is approved or not. You can simply use that field. If it is not active, it is "Uncategorized.
A more flexible way than adding one isApproved (or rather a more generic name like status) column to your table is to create a whole new temporary table. There are number of reasons why this is the better approach:
You can save diagnostical information like who created this category, when did he create it, and so on.
You separate your logic: An unapproved entry is, simply put, a temporary one. Approving it is nothing more than moving it over to your categories table and thus making it permanent.
Your categories table doesn't get clustered with unnecessary entries.
My client needs to select many categories for his article, but one category should act as main category.
Would it be better to model relationship as many to many and add column flag "is_main" to article_category table or use one to many for main category?
I am also trying to find some jquery widget to easilly implement function like this.
I thought about using jquery ui dragable to let him move categories between 3 divs: article main category, article regular categories and ALL CATEGORIES available in cms.
ALternatively I could use select for main category and checkboxes for the rest?
Maybe there is some ready solution?
I am building a website of engineering and construction in which I have list of products such as bridge, towers and all are linked. When the user clicks on bridge then its type appears from mysql table on the same page which is in the form of image but the problem is again I want to retrieve the value i.e. its sub-types which are also images. And then when user clicks that image its details will be appeared. Basically its a hierarchy up to 3-4 levels. But don't know how to make relationships between tables.
If the items in your hierarchy can be generalized enough, you could make a single table with the columns: id, parent, information
One entry could be id=Bridge, Parent=Architecture, information=picture_source
You can then make lookups like, show me every entry that has Architecture as its parent and send the list to the client.
Use InnoDB engine for mysql. MyISAM don't support foreign keys (if you are using the default).
you can use:
ALTER TABLE table_name ENGINE=InnoDB;
use parent -child relationships like this,
example:
when clicked on bridge - take data from child 1 table having same fk-key from main table ,
so your all bridge types will appear
Do same for all your sub items
i have made a static drop-down menu for my e-commerce website. i have various categories and then sub categories.
my main tabs are, "CLOTHES", "FOOTWEAR", "ACCESSORIES" etc.
The clothes tab is divided into two parts one is brand wise and one is type(shirts, jeans, etc.)
Now my question is, if i go to the clothes tab and then click on shirts, how can i traverse and retrieve the records from my SQL table.
I have made the connection with the database, my table name is 'products'. The page to display products is list.php.
I am new to PHP and i know a little bit about this language.
have a pages table and categories table
also have cat_parent in the categories table
Then have a php loop to go through each topmost categories and then subcats and ......... and then pages.
watch it in action this is the site i am working a the moment
First you should have categories & sub categories in single 'categories' DB table.
In products table, you will have a category_id column as foreign key.
So based on this category_id column, you can retrieve products from your DB.
Also each product in DB should have assigned a particular category.
You have to use AJAX or a Javascript function to achieve this type of functionality. Here is how:
Use an onChange event in your static drop down menu HTML code.
Make a function in a <script> tag to catch the id of selected item.
Pass this id to the PHP file in the URL.
Give your <div> id name in this Javascript code.
After calling the PHP file catch the id from get method and pass it to the query.
You can get the desired result.
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.