View Full Version : Not sure where I've gone wrong...
iainmacdonald331081
09-01-2011, 08:20 AM
As above really - as far as I can tell I've followed the instruction, but this is the current state of my test page:
http://www.gbp.uk.com/admin/addProduct.php
One thing I wasn't sure about was the instruction to set them as lists, rather than drop down menus?
Anyway - I have attached a copy of the page, and would be grateful if someone could have a quick look and see if they can spot what I've missed.
Thanks again.
Jason Byrnes
09-01-2011, 08:55 AM
you have applied the Populate List from array behavior to the onchange event of the child form element.
it needs to be applied to the onchange event of the parent form element instead.
iainmacdonald331081
09-01-2011, 11:54 AM
Thanks Jason - have now changed that, but still isn't working here:
http://www.gbp.uk.com/admin/addProduct.php
I've attached a copy of the current page.
My database structure for the Parent and Child tables are as follows:
Parent:
Table: categories
Fields: category_ID, category
Table: subcategories: SubCategoryID, SubCategory, CategoryLinkID
Jason Byrnes
09-01-2011, 11:57 AM
in the category list, you are passing the category name as the value:
<option value="Cladding">Cladding</option>
it needs to pass the category id
iainmacdonald331081
09-01-2011, 12:30 PM
Thanks Jason - that's the drop downs working now:
http://www.gbp.uk.com/admin/addProduct.php
The last part now is that I'm not sure how to write the selected values into the database table (Products).
The Parent value (categories, category) needs to go into the field Main_Category, and the Child value (subcategories, SubCategory) into 1st_Sub.
The original insert code before the drop downs looked like:
// Add columns
$ins_Products->setTable("Products");
$ins_Products->addColumn("Category_ID", "NUMERIC_TYPE", "POST", "Category_ID");
$ins_Products->addColumn("Main_Category", "STRING_TYPE", "POST", "Main_Category");
$ins_Products->addColumn("Product_Code", "STRING_TYPE", "POST", "Product_Code");
$ins_Products->addColumn("1st_Sub", "STRING_TYPE", "POST", "1st_Sub");
$ins_Products->addColumn("2nd_Sub", "STRING_TYPE", "POST", "2nd_Sub");
$ins_Products->addColumn("Colour", "STRING_TYPE", "POST", "Colour");
$ins_Products->addColumn("Colour_image", "STRING_TYPE", "POST", "Colour_image");
$ins_Products->addColumn("Product_Description", "STRING_TYPE", "POST", "Product_Description");
$ins_Products->addColumn("Price", "DOUBLE_TYPE", "POST", "Price");
$ins_Products->addColumn("Image", "FILE_TYPE", "FILES", "Image");
$ins_Products->setPrimaryKey("Product_ID", "NUMERIC_TYPE");
I tried changing the relevant lines:
$ins_Products->addColumn("Main_Category", "STRING_TYPE", "POST", "Main_Category");
$ins_Products->addColumn("1st_Sub", "STRING_TYPE", "POST", "1st_Sub");
to the fields referenced in the drop downs:
$ins_Products->addColumn("Main_Category", "STRING_TYPE", "POST", "category");
$ins_Products->addColumn("1st_Sub", "STRING_TYPE", "POST", "SubCategory");
but that didn't seem to work.
Jason Byrnes
09-01-2011, 01:09 PM
the select lists are not named category and SubCategory, they are named Parent and Child
$ins_Products->addColumn("Main_Category", "STRING_TYPE", "POST", "Parent");
$ins_Products->addColumn("1st_Sub", "STRING_TYPE", "POST", "Child");
iainmacdonald331081
09-01-2011, 02:45 PM
Nearly, but not quite - Parent inserts category_ID rather than category, and Child inserts SubCategoryID rather than SubCategory...
Jason Byrnes
09-01-2011, 03:21 PM
it is supposed to work that way.
category and sub category names are defined in the category and subcategory tables.
in the product table, you want to store the category and sub category ID.
you return the associated name by using a join query.
for more details on join queries, see the following page:
http://www.w3schools.com/sql/sql_join.asp
iainmacdonald331081
09-01-2011, 03:57 PM
OK - I'm just about familiar with joins, link IDs etc, but was just keeping it simple here as per the instructions to get the dropdowns working.
So in the Products table I have the fields Main_Category and 1st_Sub which correspond to category in the Categories table and SubCategory in the subcategories table.
With the join, do I need to link the Products table to the categories and/or subcategories tables in the Parent and/or Child recordsets?
iainmacdonald331081
09-01-2011, 04:49 PM
Hold on - just looking at this again, and think I've figured out what I should be doing....
Should I basically drop the text fields from the main Products table for Category and SubCategory, but rather just have CategoryID and SubCategoryID.
And then have tables Categories and SubCategories.
And then in the pages that list each category, use the join query on those pages to look up Category and SubCategory in the Categories and SubCategories tables?
Jason Byrnes
09-02-2011, 06:25 AM
Should I basically drop the text fields from the main Products table for Category and SubCategory, but rather just have CategoryID and SubCategoryID.
And then have tables Categories and SubCategories.
And then in the pages that list each category, use the join query on those pages to look up Category and SubCategory in the Categories and SubCategories tables?
Edit/Delete Message
yes, that is it exactly,
One table for categories, another table for subcatagories and another table for products:
categories:
categoryID - primary key
categoryName - text
subcategories
subcatID - Primary Key
subcatCategoryID - integer - relates to categories.categoryID
subcatName - text
products:
productID - Primary key
productCatID - integer - relate to categories.categoryID
productSubCatID - integer - relates to subcategories.subcatID
productName - text
etc.....
vBulletin® v3.8.1, Copyright ©2000-2012, Jelsoft Enterprises Ltd.