How to insert multiple records using one query if the number of repetitions are different from each otherinsert into table with multiple records from multiple tablesSQL query return data from multiple tablesMySQL insert query inserting more than one record at a timeCopying a row from one mysql table to another table, and modifying field valuesInserting multiple rows from php foreachCombining 4 elements (nested loops)How to extract data which lies in a range in SqlCollecting records from different sites in a single MySQLHow to perform insert in one query?Query: SUM, AVG 3 days of data?
"My boss was furious with me and I have been fired" vs. "My boss was furious with me and I was fired"
Why didn't the Space Shuttle bounce back into space as many times as possible so as to lose a lot of kinetic energy up there?
Multiple fireplaces in an apartment building?
Do I need to watch Ant-Man and the Wasp and Captain Marvel before watching Avengers: Endgame?
How to not starve gigantic beasts
Which big number is bigger?
Apply a different color ramp to subset of categorized symbols in QGIS?
How do I produce this symbol: Ϟ in pdfLaTeX?
Double-nominative constructions and “von”
Can a level 2 Warlock take one level in rogue, then continue advancing as a warlock?
Magical attacks and overcoming damage resistance
How bug prioritization works in agile projects vs non agile
Find a stone which is not the lightest one
Island of Knights, Knaves and Spies
How to keep bees out of canned beverages?
Crossed out red box fitting tightly around image
What to do with someone that cheated their way through university and a PhD program?
Does the damage from the Absorb Elements spell apply to your next attack, or to your first attack on your next turn?
Was Dennis Ritchie being too modest in this quote about C and Pascal?
`microtype`: Set Minimum Width of a Space
Why doesn't the standard consider a template constructor as a copy constructor?
As an international instructor, should I openly talk about my accent?
Why do games have consumables?
Restricting the options of a lookup field, based on the value of another lookup field?
How to insert multiple records using one query if the number of repetitions are different from each other
insert into table with multiple records from multiple tablesSQL query return data from multiple tablesMySQL insert query inserting more than one record at a timeCopying a row from one mysql table to another table, and modifying field valuesInserting multiple rows from php foreachCombining 4 elements (nested loops)How to extract data which lies in a range in SqlCollecting records from different sites in a single MySQLHow to perform insert in one query?Query: SUM, AVG 3 days of data?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm really confused about how to insert data into the table using one query when you've different number of items that are you trying to insert.
I'm thinking of the table should look like this.
TABLE
day start startGrams breakfast breakfastGrams
Example:
Consider this image
In the image the user would able to enter grams for the food items for different days,from the front end side.
On maandag (Monday) at START, let say user has entered grams for whey protein and water.
and on the same day i.e monday let he want to enter BREAKFAST grams only for water.
How many time should I run the insert query because in the first I've to insert grams for 2 food items and then for one food item.
I'm assuming to grab all the grams fields and then insert into the table through one query.
How to solve this problem ?
php mysql
|
show 5 more comments
I'm really confused about how to insert data into the table using one query when you've different number of items that are you trying to insert.
I'm thinking of the table should look like this.
TABLE
day start startGrams breakfast breakfastGrams
Example:
Consider this image
In the image the user would able to enter grams for the food items for different days,from the front end side.
On maandag (Monday) at START, let say user has entered grams for whey protein and water.
and on the same day i.e monday let he want to enter BREAKFAST grams only for water.
How many time should I run the insert query because in the first I've to insert grams for 2 food items and then for one food item.
I'm assuming to grab all the grams fields and then insert into the table through one query.
How to solve this problem ?
php mysql
why do you want to do it in one query?
– kuh-chan
Mar 22 at 16:37
@kuh-chan Why wouldn't you?
– Strawberry
Mar 22 at 16:37
what else I could do ? @kuh-chan
– Nprogrammer
Mar 22 at 16:39
@Strawberry I'd make a prepared insert and run a loop over the post data to insert them with parameter binding
– kuh-chan
Mar 22 at 16:39
1
Without fixing your design, this is a hopeless course of action.
– Strawberry
Mar 22 at 16:41
|
show 5 more comments
I'm really confused about how to insert data into the table using one query when you've different number of items that are you trying to insert.
I'm thinking of the table should look like this.
TABLE
day start startGrams breakfast breakfastGrams
Example:
Consider this image
In the image the user would able to enter grams for the food items for different days,from the front end side.
On maandag (Monday) at START, let say user has entered grams for whey protein and water.
and on the same day i.e monday let he want to enter BREAKFAST grams only for water.
How many time should I run the insert query because in the first I've to insert grams for 2 food items and then for one food item.
I'm assuming to grab all the grams fields and then insert into the table through one query.
How to solve this problem ?
php mysql
I'm really confused about how to insert data into the table using one query when you've different number of items that are you trying to insert.
I'm thinking of the table should look like this.
TABLE
day start startGrams breakfast breakfastGrams
Example:
Consider this image
In the image the user would able to enter grams for the food items for different days,from the front end side.
On maandag (Monday) at START, let say user has entered grams for whey protein and water.
and on the same day i.e monday let he want to enter BREAKFAST grams only for water.
How many time should I run the insert query because in the first I've to insert grams for 2 food items and then for one food item.
I'm assuming to grab all the grams fields and then insert into the table through one query.
How to solve this problem ?
php mysql
php mysql
asked Mar 22 at 16:36
NprogrammerNprogrammer
84
84
why do you want to do it in one query?
– kuh-chan
Mar 22 at 16:37
@kuh-chan Why wouldn't you?
– Strawberry
Mar 22 at 16:37
what else I could do ? @kuh-chan
– Nprogrammer
Mar 22 at 16:39
@Strawberry I'd make a prepared insert and run a loop over the post data to insert them with parameter binding
– kuh-chan
Mar 22 at 16:39
1
Without fixing your design, this is a hopeless course of action.
– Strawberry
Mar 22 at 16:41
|
show 5 more comments
why do you want to do it in one query?
– kuh-chan
Mar 22 at 16:37
@kuh-chan Why wouldn't you?
– Strawberry
Mar 22 at 16:37
what else I could do ? @kuh-chan
– Nprogrammer
Mar 22 at 16:39
@Strawberry I'd make a prepared insert and run a loop over the post data to insert them with parameter binding
– kuh-chan
Mar 22 at 16:39
1
Without fixing your design, this is a hopeless course of action.
– Strawberry
Mar 22 at 16:41
why do you want to do it in one query?
– kuh-chan
Mar 22 at 16:37
why do you want to do it in one query?
– kuh-chan
Mar 22 at 16:37
@kuh-chan Why wouldn't you?
– Strawberry
Mar 22 at 16:37
@kuh-chan Why wouldn't you?
– Strawberry
Mar 22 at 16:37
what else I could do ? @kuh-chan
– Nprogrammer
Mar 22 at 16:39
what else I could do ? @kuh-chan
– Nprogrammer
Mar 22 at 16:39
@Strawberry I'd make a prepared insert and run a loop over the post data to insert them with parameter binding
– kuh-chan
Mar 22 at 16:39
@Strawberry I'd make a prepared insert and run a loop over the post data to insert them with parameter binding
– kuh-chan
Mar 22 at 16:39
1
1
Without fixing your design, this is a hopeless course of action.
– Strawberry
Mar 22 at 16:41
Without fixing your design, this is a hopeless course of action.
– Strawberry
Mar 22 at 16:41
|
show 5 more comments
1 Answer
1
active
oldest
votes
Not an answer; too long for a comment...
A normalised schema might look something like this. Note that there is likely further scope for normalisation, but it's a start...
schedule
day session meal_id
monday start 1
monday breakfast 1
tuesday start 1
tuesday breakfast 1
meal_detail
meal_id ingredient_id quantity unit
1 101 80 gr
1 102 30 gr
1 103 118 gr
1 104 24 gr
1 105 21 gr
1 100 237 gr
ingredients
ingredient_id name
100 water (1 cup)
101 havermout
102 whey protein
103 banaan (1 med.)
104 pindakaas
105 honing (1 tl)
I'm sure this will help me a lot, @strawberry thank you so much !
– Nprogrammer
Mar 22 at 16:57
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55304115%2fhow-to-insert-multiple-records-using-one-query-if-the-number-of-repetitions-are%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Not an answer; too long for a comment...
A normalised schema might look something like this. Note that there is likely further scope for normalisation, but it's a start...
schedule
day session meal_id
monday start 1
monday breakfast 1
tuesday start 1
tuesday breakfast 1
meal_detail
meal_id ingredient_id quantity unit
1 101 80 gr
1 102 30 gr
1 103 118 gr
1 104 24 gr
1 105 21 gr
1 100 237 gr
ingredients
ingredient_id name
100 water (1 cup)
101 havermout
102 whey protein
103 banaan (1 med.)
104 pindakaas
105 honing (1 tl)
I'm sure this will help me a lot, @strawberry thank you so much !
– Nprogrammer
Mar 22 at 16:57
add a comment |
Not an answer; too long for a comment...
A normalised schema might look something like this. Note that there is likely further scope for normalisation, but it's a start...
schedule
day session meal_id
monday start 1
monday breakfast 1
tuesday start 1
tuesday breakfast 1
meal_detail
meal_id ingredient_id quantity unit
1 101 80 gr
1 102 30 gr
1 103 118 gr
1 104 24 gr
1 105 21 gr
1 100 237 gr
ingredients
ingredient_id name
100 water (1 cup)
101 havermout
102 whey protein
103 banaan (1 med.)
104 pindakaas
105 honing (1 tl)
I'm sure this will help me a lot, @strawberry thank you so much !
– Nprogrammer
Mar 22 at 16:57
add a comment |
Not an answer; too long for a comment...
A normalised schema might look something like this. Note that there is likely further scope for normalisation, but it's a start...
schedule
day session meal_id
monday start 1
monday breakfast 1
tuesday start 1
tuesday breakfast 1
meal_detail
meal_id ingredient_id quantity unit
1 101 80 gr
1 102 30 gr
1 103 118 gr
1 104 24 gr
1 105 21 gr
1 100 237 gr
ingredients
ingredient_id name
100 water (1 cup)
101 havermout
102 whey protein
103 banaan (1 med.)
104 pindakaas
105 honing (1 tl)
Not an answer; too long for a comment...
A normalised schema might look something like this. Note that there is likely further scope for normalisation, but it's a start...
schedule
day session meal_id
monday start 1
monday breakfast 1
tuesday start 1
tuesday breakfast 1
meal_detail
meal_id ingredient_id quantity unit
1 101 80 gr
1 102 30 gr
1 103 118 gr
1 104 24 gr
1 105 21 gr
1 100 237 gr
ingredients
ingredient_id name
100 water (1 cup)
101 havermout
102 whey protein
103 banaan (1 med.)
104 pindakaas
105 honing (1 tl)
answered Mar 22 at 16:49
StrawberryStrawberry
26.8k83250
26.8k83250
I'm sure this will help me a lot, @strawberry thank you so much !
– Nprogrammer
Mar 22 at 16:57
add a comment |
I'm sure this will help me a lot, @strawberry thank you so much !
– Nprogrammer
Mar 22 at 16:57
I'm sure this will help me a lot, @strawberry thank you so much !
– Nprogrammer
Mar 22 at 16:57
I'm sure this will help me a lot, @strawberry thank you so much !
– Nprogrammer
Mar 22 at 16:57
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55304115%2fhow-to-insert-multiple-records-using-one-query-if-the-number-of-repetitions-are%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
why do you want to do it in one query?
– kuh-chan
Mar 22 at 16:37
@kuh-chan Why wouldn't you?
– Strawberry
Mar 22 at 16:37
what else I could do ? @kuh-chan
– Nprogrammer
Mar 22 at 16:39
@Strawberry I'd make a prepared insert and run a loop over the post data to insert them with parameter binding
– kuh-chan
Mar 22 at 16:39
1
Without fixing your design, this is a hopeless course of action.
– Strawberry
Mar 22 at 16:41