Update combo depending on previous combo information - javascript

I have this two tables.
id
city
1
bogota
2
tunja
id
branch
cityid
1
sector1
1
2
sector2
2
3
sector3
2
4
sector4
1
now i need to create a way in which the branch select field updates depending on the foreign key of the city
example:
my first combo should contain city bogota and the next combo should only show me the list of branches that are part of that particular city.
how to begin?

Related

create Google form by appscript and then add items after taking the responses

I have a school data where there are more than 300 students in diffrent classes now I have to create a register using Google form. So i created a google form with option asGridItem. With column as present and absent and set its Row as student admission no. From my spreadsheet but the problem is I have to update this row such that if a new student get added in that spreadsheet google form update itself. but the problem is with my code it doesn't edit the spreadsheet but the code set another value and deleted the previous one which mess up my response that I don't want. I want to edit that existing row and add the new student or delete that student from the Form row and not edit my entire form.
function edit() {
var form = FormApp.openById("formid");
var class1 = form.getItemById("itemid").asGridItem();
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("sheetname");
var val = sheet.getRange(2, 1, sheet.getLastRow() - 1, sheet.getlastcolumn()).getValues();
var filter = val.filter(r => { return r[0].toString() === "1" }).map(t => t[2]);
class1.setRows(filter);
}
this is the code it give response as
1 2 3
but when I add '4' to spreadsheet it will give response like this ->
1 2 3
1 2 3 4
But I don't want my response to look like that I want my response to look like this->
1 2 3
1 2 3 4
Start from begning again not from the bottom and yes I have checked all the other question which is similar to mine but no none of them giving me the response sheet that I want.

avoid - aggregation in ag-grid

i have ag-grid. This is the column structure -
account share qty
i'm grouping by account (rowGroup = true). I have this sample data -
account
share
qty
234
xny
4
234
ghy
3
this appears as
account
share
qty
234
0
xny
4
ghy
3
note that 0 comes for qty. this is because i havenot provided any aggregateFunction to colDef.
I want that qty cell to be empty for group level records (instead of showing a zero). is there a way to do it?
I'm not sure if this is the correct way but I was able to solve this by checking if the row is a group level row in my value formatter.
if the row is a group level row, i would return an empty string. otherwise, i would invoke the formatting function to show formatted data.

comparing two tables with mysql

I tried to search for an answer to this but I'm not sure if there are any answers to this question because I'm not quite sure how to word it correctly... Here I have two tables
Recipe ingredient table
Recipe_id|ingredient_id
ifqvv |1
ifqvv |2
User ingredient table
User_id|ingredient_id
1 |1
1 |2
2 |1
3 |3
I need to compare these table to where if both recipe and user ingredients_id are a complete match it will return a 1, or if the ingredients are greater than 0 it'll return a 2, and 3 for no matches. For Example, a query for User 1 will return a 1, User 2 a 2, and User 3 a 3. I'm not sure if this is something I'll have to code but I was told by someone that this is possible with little information, which led me here
Assuming you also have a user table, you could achieve this by cross-joining the user with the recipe_ingredients table and then left-joining the user_ingredients table, e.g.:
SELECT u.user_id, ri.recipe_id,
COUNT(ui.ingredient_id) AS available_ingredients, -- Number of ingredients the user has that are required to cook this recipe
COUNT(ri.ingredient_id) AS required_ingredients, -- Number of ingredients that are required to cook this recipe
CASE
WHEN COUNT(ui.ingredient_id) = COUNT(ri.ingredient_id) THEN 'can_cook'
WHEN COUNT(ui.ingredient_id) > 0 THEN 'has_some_ingredients'
ELSE 'has_no_ingredients'
END AS state
FROM users u
CROSS JOIN recipe_ingredients ri
LEFT JOIN user_ingredients ui ON(ri.ingredient_id = ui.ingredient_id AND u.user_id = ui.user_id)
GROUP BY u.user_id, ri.recipe_id
ORDER BY u.user_id, ri.recipe_id
If you want to limit it to a certain user / recipe, just use a where clause:
WHERE u.user_id = 1 AND ri.recipe_id = 'ifqvv'
You can try it live here: DB Fiddle
If you don't have an users table then you can replace
FROM users u with FROM (SELECT DISTINCT user_id FROM user_ingredients) u
DB Fiddle

Depending selects in symfony2

I have two selects, where the user chooses the first product to carry, and I want you automatically in the second quantities of the product that can be loaded.
Examples:
If you choose dishes , it can lead to a 6, 12 or 24 dishes. However , if you choose glasses , it can take one of a 5 or a 10. I'm working on Symfony2 and have an entity called Categories , which has 1 field ' category ' , and a ratio of 1 to many with another entity having the amounts by which the products of that category ( of 6 , 12, 24 ) are sold . and then I have a relationship of one to many with the entity 'Products' where all the products in each category .
I'm told you do with AJAX, but nevertheless not how.

Create table with nested rows for each parent row

Table 1
orderid customerName totalCost
----------------------------------
1 Jonh £200.00
2 Ringo £50
Table 2
orderlineid orderid productName productPrice Quantity
-------------------------------------------------------
1 1 Product1 £150 1
2 1 Product2 £50 1
3 2 Product3 £50 1
Table 3
orderid customerName totalCost
---------------------------------------
1 John £200
---------------------------------------
+ 1 1 Product1 £150 1
+ 2 1 Product2 £50 1
---------------------------------------
2 Ringo £50
---------------------------------------
+ 3 2 Product3 £50
Is it possible (given tables 1 and 2) to create an HTML table similar to table 3? Where for each order underneath there are the orders corresponding order lines information
Thanks
It's not possible to make a single table with real* nested relationships in SQL. Each SQL table is nothing more than a big two dimensional grid, no exceptions.
The correct way to store this type of relationship is in multiple tables, as you already have done.
You haven't said why you are trying to do this, but it sounds like it is a requirement for display rather than for storage. If so, the answer is to have whatever is producing the display query multiple tables as appropriate to get the information you need. This might be a single SQL query with a join, or it might be multiple queries. That depends on having more information about what you are doing.
*Sometimes nested relationships can be modeled within the rigid structure of a single table, but that isn't appropriate in your case.

Categories