I have 2 mysql tables one contains category mapping relationships between a supplier and our store: Basically what we call their categories eg ~ denotes sub category level:
Cateogry Mapping Relationship Table
Supplier Cat..........| Our Cat.....
dogs~leashes~long.....| pets~walking
dogs~leashes~long.....| pets~travel
dogs~leashes~short....| pets~walking
dogs~leashes~nylon....| pets~walking
dogs~feeding .........| pets~feeding
the other table contains supplier item ids with the categories that the supplier has the products in. Multiple categories are concatenated in the same field with a ','.
Such as the following:
Supplier Item Table
Supplier item ID...| Supplier item Categories
28374 ............| dogs~leashes~long,dogs~leashes~nylon
My task is to replace the item paths in the supplier list with the correct paths from our store category list so I can put them in our database.
So the result of the php / mysql function Im trying to build for the above data modification would be (I dont care if I run this in php or mysql which ever is easier to get the job done.):
Supplier item..| Supplier item Categories ..............| New item Categories
28374 ........| dogs~leashes~long,dogs~leashes~nylon ..|pets~travel,pets~walking
Im not sure how to handle the concatenated field and I would appreciate any help at all
thank you
write a query that selects id,cat from supplier item table
In a php loop split the category by ',' and do a select to get your category
write into a new table id/your category
check new table for validity
delete old table and rename new table
Related
I have 2 tables in the Database.
One contains a list of Inventories with name, creation date and ID.
The second table contains individual products, and one column here contains IDs from the Inventory List table.
I write all inventories from the inventory list to the Frontend. There is a detail button next to each listed inventory and after clicking it I need to list all the products with the corresponding inventory ID.
But somehow I can't figure out what to use for it?
Could you please advise me what such a query should contain?
In my project I want to query orders. every food have a category and every category have a parent. so my problem is some orders have two type parent category. like Indian food and italian food in one order. I used select multiple element. and parent categories are shown inside it. one another item is all. so when user selects all parent categories the orders that have two type of categories like explained above it's shows more than 1 in table and I have no idea how to select only one of this duplicate fields.
my query code is :
if (isset($subset) && $subset!=""){
$query->leftJoin('z_food_orders','z_food_orders.order_id','=','z_orders.id')
->leftJoin('z_foods','z_food_orders.food_id','=','z_foods.id')
->leftJoin('z_food_cats','z_foods.cat_id','=','z_food_cats.id')
->leftJoin('z_res_subset','z_food_cats.parent_id','=','z_res_subset.id');
if (count($subset) == 1){
$query->where('z_res_subset.id',$subset);
}else{
$query->whereIn('z_res_subset.id',$subset);
}
}
Developing a PHP Slim application and I'm using RedBean ORM to interact with the database (MySQL) I have an employees table and categories table I need to load the values from the categories table according to the category the employee belongs to and show them in the employee details. Like the category name, base pay, tax e.t.c.
So when I select the employee the details of the category in which he belongs to are shown( read from the categories DB)
I have tried loading the values by accessing this output by reading association like this
$category = R::dispense('category');
$employees = R::related($category, "employee");
but the above does not return anything. Any help is welcome
I have to create a web site witch contain goods. these goods have their own categories.for a
example a good can be categorized in many categories or sub categories.
I already have a item table witch contain their properties. and can anyone say how to keep it`s categories in database without duplicating data
Ok. In this case an Item may have many categories and a category may have many Items. So its a many to many relationship. Try as follows,
Your Item table may look like this,
Item(id, description, amount, ... )
In your Category table,
Category(id, name, description, ... )
And there will be another table to assign categories to items,
ItemCategoryAssignments(itemId, categoryId)
And there will be two foreign keys at ItemCategoryAssignments table. That,
itemId references id in the Item tabel
and
categoryId references id in the Category tabel
Like that. There will be no duplicated rows. Hope this will help.
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.