Q: Insert data into loop statement











up vote
0
down vote

favorite
1












Good morning,



I'd hate to bother you all with what may be the simplest question/solution of all, but it appears that no matter what current articles I've read on stack overflow or even my own attempts at a resolution I can't seem to have the response I'm looking for.



What i've been trying to work on this whole week was being able to obtain the User ID (uid) from an invoice list and then insert that same ID over to a new table called convo_sent, problem is that the following code (shown below) doesn't insert the content more than once when there is more than one string to pull from within invoice_id:



SQL Table(s):



**invoices** table.

Id | uid | invoice_id
1 | 2 | 1
2 | 20 | 3
3 | 4 | 10
4 | 60 | 1


**convo_sent** table.

Id | uid | sid | action | action_id | date | seen
1 | 1 | 90 | sent | 1 | n/a | 1
2 | 10 | 85 | sent | 1 | n/a | 0
3 | 7 | 270 | no_payment | 0 | n/a | 0
4 | 6 | 400 | sent | 1 | n/a | 1


Script in question:



 $sql="select uid from invoices where invoice_id = '1'";
$res=mysql_query($sql);
while($data_set=mysql_fetch_array($res))
{
$date=date("l, F j, Y h:i a", TIME());
$sid=$_SESSION["mid"];
$fid=$data_set["uid"];

$sql="insert into convo_sent";
$sql.="(uid";
$sql.=", sid";
$sql.=", action";
$sql.=", action_id";
$sql.=", seen";
$sql.=", time)";

$sql.=" values('$fid' ";
$sql.=", '$sid'";
$sql.=", 'test'";
$sql.=", '0'";
$sql.=", '0'";
$sql.=", '$date')";
$res = mysql_query($sql);
$sr_no=$sr_no+1;
}


What I believe happens is that although the statement (by itself, without the insert method) is able to loop through and pull the information I needed. When you're trying to use the insert method, perhaps the statement (looping) can only submit the first user ID and nothing else.










share|improve this question
























  • Where is member_id column in invoices table?
    – Samir
    Nov 11 at 10:32










  • @Samir - Corrected the code, sorry. $data_set["uid"] replaces $data_set["member_id"] and $_SESSION["member_id"] is replaced by $_SESSION["mid"]; The code itself has been changed a bit from the original for easier understanding.
    – Ronnie
    Nov 11 at 10:37












  • Do echo $sql and check how many times it loops inside while.
    – Samir
    Nov 11 at 11:03










  • @Samir - Good question, will try it out.
    – Ronnie
    Nov 11 at 13:52










  • @Samir - looped only once and it's always the last integer.
    – Ronnie
    Nov 11 at 13:53















up vote
0
down vote

favorite
1












Good morning,



I'd hate to bother you all with what may be the simplest question/solution of all, but it appears that no matter what current articles I've read on stack overflow or even my own attempts at a resolution I can't seem to have the response I'm looking for.



What i've been trying to work on this whole week was being able to obtain the User ID (uid) from an invoice list and then insert that same ID over to a new table called convo_sent, problem is that the following code (shown below) doesn't insert the content more than once when there is more than one string to pull from within invoice_id:



SQL Table(s):



**invoices** table.

Id | uid | invoice_id
1 | 2 | 1
2 | 20 | 3
3 | 4 | 10
4 | 60 | 1


**convo_sent** table.

Id | uid | sid | action | action_id | date | seen
1 | 1 | 90 | sent | 1 | n/a | 1
2 | 10 | 85 | sent | 1 | n/a | 0
3 | 7 | 270 | no_payment | 0 | n/a | 0
4 | 6 | 400 | sent | 1 | n/a | 1


Script in question:



 $sql="select uid from invoices where invoice_id = '1'";
$res=mysql_query($sql);
while($data_set=mysql_fetch_array($res))
{
$date=date("l, F j, Y h:i a", TIME());
$sid=$_SESSION["mid"];
$fid=$data_set["uid"];

$sql="insert into convo_sent";
$sql.="(uid";
$sql.=", sid";
$sql.=", action";
$sql.=", action_id";
$sql.=", seen";
$sql.=", time)";

$sql.=" values('$fid' ";
$sql.=", '$sid'";
$sql.=", 'test'";
$sql.=", '0'";
$sql.=", '0'";
$sql.=", '$date')";
$res = mysql_query($sql);
$sr_no=$sr_no+1;
}


What I believe happens is that although the statement (by itself, without the insert method) is able to loop through and pull the information I needed. When you're trying to use the insert method, perhaps the statement (looping) can only submit the first user ID and nothing else.










share|improve this question
























  • Where is member_id column in invoices table?
    – Samir
    Nov 11 at 10:32










  • @Samir - Corrected the code, sorry. $data_set["uid"] replaces $data_set["member_id"] and $_SESSION["member_id"] is replaced by $_SESSION["mid"]; The code itself has been changed a bit from the original for easier understanding.
    – Ronnie
    Nov 11 at 10:37












  • Do echo $sql and check how many times it loops inside while.
    – Samir
    Nov 11 at 11:03










  • @Samir - Good question, will try it out.
    – Ronnie
    Nov 11 at 13:52










  • @Samir - looped only once and it's always the last integer.
    – Ronnie
    Nov 11 at 13:53













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





Good morning,



I'd hate to bother you all with what may be the simplest question/solution of all, but it appears that no matter what current articles I've read on stack overflow or even my own attempts at a resolution I can't seem to have the response I'm looking for.



What i've been trying to work on this whole week was being able to obtain the User ID (uid) from an invoice list and then insert that same ID over to a new table called convo_sent, problem is that the following code (shown below) doesn't insert the content more than once when there is more than one string to pull from within invoice_id:



SQL Table(s):



**invoices** table.

Id | uid | invoice_id
1 | 2 | 1
2 | 20 | 3
3 | 4 | 10
4 | 60 | 1


**convo_sent** table.

Id | uid | sid | action | action_id | date | seen
1 | 1 | 90 | sent | 1 | n/a | 1
2 | 10 | 85 | sent | 1 | n/a | 0
3 | 7 | 270 | no_payment | 0 | n/a | 0
4 | 6 | 400 | sent | 1 | n/a | 1


Script in question:



 $sql="select uid from invoices where invoice_id = '1'";
$res=mysql_query($sql);
while($data_set=mysql_fetch_array($res))
{
$date=date("l, F j, Y h:i a", TIME());
$sid=$_SESSION["mid"];
$fid=$data_set["uid"];

$sql="insert into convo_sent";
$sql.="(uid";
$sql.=", sid";
$sql.=", action";
$sql.=", action_id";
$sql.=", seen";
$sql.=", time)";

$sql.=" values('$fid' ";
$sql.=", '$sid'";
$sql.=", 'test'";
$sql.=", '0'";
$sql.=", '0'";
$sql.=", '$date')";
$res = mysql_query($sql);
$sr_no=$sr_no+1;
}


What I believe happens is that although the statement (by itself, without the insert method) is able to loop through and pull the information I needed. When you're trying to use the insert method, perhaps the statement (looping) can only submit the first user ID and nothing else.










share|improve this question















Good morning,



I'd hate to bother you all with what may be the simplest question/solution of all, but it appears that no matter what current articles I've read on stack overflow or even my own attempts at a resolution I can't seem to have the response I'm looking for.



What i've been trying to work on this whole week was being able to obtain the User ID (uid) from an invoice list and then insert that same ID over to a new table called convo_sent, problem is that the following code (shown below) doesn't insert the content more than once when there is more than one string to pull from within invoice_id:



SQL Table(s):



**invoices** table.

Id | uid | invoice_id
1 | 2 | 1
2 | 20 | 3
3 | 4 | 10
4 | 60 | 1


**convo_sent** table.

Id | uid | sid | action | action_id | date | seen
1 | 1 | 90 | sent | 1 | n/a | 1
2 | 10 | 85 | sent | 1 | n/a | 0
3 | 7 | 270 | no_payment | 0 | n/a | 0
4 | 6 | 400 | sent | 1 | n/a | 1


Script in question:



 $sql="select uid from invoices where invoice_id = '1'";
$res=mysql_query($sql);
while($data_set=mysql_fetch_array($res))
{
$date=date("l, F j, Y h:i a", TIME());
$sid=$_SESSION["mid"];
$fid=$data_set["uid"];

$sql="insert into convo_sent";
$sql.="(uid";
$sql.=", sid";
$sql.=", action";
$sql.=", action_id";
$sql.=", seen";
$sql.=", time)";

$sql.=" values('$fid' ";
$sql.=", '$sid'";
$sql.=", 'test'";
$sql.=", '0'";
$sql.=", '0'";
$sql.=", '$date')";
$res = mysql_query($sql);
$sr_no=$sr_no+1;
}


What I believe happens is that although the statement (by itself, without the insert method) is able to loop through and pull the information I needed. When you're trying to use the insert method, perhaps the statement (looping) can only submit the first user ID and nothing else.







php sql insert






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 10:36

























asked Nov 11 at 10:23









Ronnie

32




32












  • Where is member_id column in invoices table?
    – Samir
    Nov 11 at 10:32










  • @Samir - Corrected the code, sorry. $data_set["uid"] replaces $data_set["member_id"] and $_SESSION["member_id"] is replaced by $_SESSION["mid"]; The code itself has been changed a bit from the original for easier understanding.
    – Ronnie
    Nov 11 at 10:37












  • Do echo $sql and check how many times it loops inside while.
    – Samir
    Nov 11 at 11:03










  • @Samir - Good question, will try it out.
    – Ronnie
    Nov 11 at 13:52










  • @Samir - looped only once and it's always the last integer.
    – Ronnie
    Nov 11 at 13:53


















  • Where is member_id column in invoices table?
    – Samir
    Nov 11 at 10:32










  • @Samir - Corrected the code, sorry. $data_set["uid"] replaces $data_set["member_id"] and $_SESSION["member_id"] is replaced by $_SESSION["mid"]; The code itself has been changed a bit from the original for easier understanding.
    – Ronnie
    Nov 11 at 10:37












  • Do echo $sql and check how many times it loops inside while.
    – Samir
    Nov 11 at 11:03










  • @Samir - Good question, will try it out.
    – Ronnie
    Nov 11 at 13:52










  • @Samir - looped only once and it's always the last integer.
    – Ronnie
    Nov 11 at 13:53
















Where is member_id column in invoices table?
– Samir
Nov 11 at 10:32




Where is member_id column in invoices table?
– Samir
Nov 11 at 10:32












@Samir - Corrected the code, sorry. $data_set["uid"] replaces $data_set["member_id"] and $_SESSION["member_id"] is replaced by $_SESSION["mid"]; The code itself has been changed a bit from the original for easier understanding.
– Ronnie
Nov 11 at 10:37






@Samir - Corrected the code, sorry. $data_set["uid"] replaces $data_set["member_id"] and $_SESSION["member_id"] is replaced by $_SESSION["mid"]; The code itself has been changed a bit from the original for easier understanding.
– Ronnie
Nov 11 at 10:37














Do echo $sql and check how many times it loops inside while.
– Samir
Nov 11 at 11:03




Do echo $sql and check how many times it loops inside while.
– Samir
Nov 11 at 11:03












@Samir - Good question, will try it out.
– Ronnie
Nov 11 at 13:52




@Samir - Good question, will try it out.
– Ronnie
Nov 11 at 13:52












@Samir - looped only once and it's always the last integer.
– Ronnie
Nov 11 at 13:53




@Samir - looped only once and it's always the last integer.
– Ronnie
Nov 11 at 13:53












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










I think you override the select statement ($res variable). Replace $res variable into your loop.



$sql="select uid from invoices where invoice_id = '1'";
$res=mysql_query($sql);
while($data_set=mysql_fetch_array($res))
{
// ...
$sql="insert into convo_sent";
// ...
$status = mysql_query($sql);
$sr_no=$sr_no+1;
}





share|improve this answer





















  • @EqualPro - Annnd just like that, you managed to solve my problem. Thank you man!!
    – Ronnie
    Nov 11 at 14:16










  • @EqualPro - Hey there, kind of came across something which I think you may have the answer for. To kind of summarize, I've been trying to use the mail() function to send messages to our clients regarding the invoices in question and it appears that those using outlook accounts are getting duplicate messages from within the same body template. I'm not sure how to proceed with resolving this.
    – Ronnie
    Nov 18 at 1:13











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',
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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247790%2fq-insert-data-into-loop-statement%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








up vote
0
down vote



accepted










I think you override the select statement ($res variable). Replace $res variable into your loop.



$sql="select uid from invoices where invoice_id = '1'";
$res=mysql_query($sql);
while($data_set=mysql_fetch_array($res))
{
// ...
$sql="insert into convo_sent";
// ...
$status = mysql_query($sql);
$sr_no=$sr_no+1;
}





share|improve this answer





















  • @EqualPro - Annnd just like that, you managed to solve my problem. Thank you man!!
    – Ronnie
    Nov 11 at 14:16










  • @EqualPro - Hey there, kind of came across something which I think you may have the answer for. To kind of summarize, I've been trying to use the mail() function to send messages to our clients regarding the invoices in question and it appears that those using outlook accounts are getting duplicate messages from within the same body template. I'm not sure how to proceed with resolving this.
    – Ronnie
    Nov 18 at 1:13















up vote
0
down vote



accepted










I think you override the select statement ($res variable). Replace $res variable into your loop.



$sql="select uid from invoices where invoice_id = '1'";
$res=mysql_query($sql);
while($data_set=mysql_fetch_array($res))
{
// ...
$sql="insert into convo_sent";
// ...
$status = mysql_query($sql);
$sr_no=$sr_no+1;
}





share|improve this answer





















  • @EqualPro - Annnd just like that, you managed to solve my problem. Thank you man!!
    – Ronnie
    Nov 11 at 14:16










  • @EqualPro - Hey there, kind of came across something which I think you may have the answer for. To kind of summarize, I've been trying to use the mail() function to send messages to our clients regarding the invoices in question and it appears that those using outlook accounts are getting duplicate messages from within the same body template. I'm not sure how to proceed with resolving this.
    – Ronnie
    Nov 18 at 1:13













up vote
0
down vote



accepted







up vote
0
down vote



accepted






I think you override the select statement ($res variable). Replace $res variable into your loop.



$sql="select uid from invoices where invoice_id = '1'";
$res=mysql_query($sql);
while($data_set=mysql_fetch_array($res))
{
// ...
$sql="insert into convo_sent";
// ...
$status = mysql_query($sql);
$sr_no=$sr_no+1;
}





share|improve this answer












I think you override the select statement ($res variable). Replace $res variable into your loop.



$sql="select uid from invoices where invoice_id = '1'";
$res=mysql_query($sql);
while($data_set=mysql_fetch_array($res))
{
// ...
$sql="insert into convo_sent";
// ...
$status = mysql_query($sql);
$sr_no=$sr_no+1;
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 11:06









EquaPro

1444




1444












  • @EqualPro - Annnd just like that, you managed to solve my problem. Thank you man!!
    – Ronnie
    Nov 11 at 14:16










  • @EqualPro - Hey there, kind of came across something which I think you may have the answer for. To kind of summarize, I've been trying to use the mail() function to send messages to our clients regarding the invoices in question and it appears that those using outlook accounts are getting duplicate messages from within the same body template. I'm not sure how to proceed with resolving this.
    – Ronnie
    Nov 18 at 1:13


















  • @EqualPro - Annnd just like that, you managed to solve my problem. Thank you man!!
    – Ronnie
    Nov 11 at 14:16










  • @EqualPro - Hey there, kind of came across something which I think you may have the answer for. To kind of summarize, I've been trying to use the mail() function to send messages to our clients regarding the invoices in question and it appears that those using outlook accounts are getting duplicate messages from within the same body template. I'm not sure how to proceed with resolving this.
    – Ronnie
    Nov 18 at 1:13
















@EqualPro - Annnd just like that, you managed to solve my problem. Thank you man!!
– Ronnie
Nov 11 at 14:16




@EqualPro - Annnd just like that, you managed to solve my problem. Thank you man!!
– Ronnie
Nov 11 at 14:16












@EqualPro - Hey there, kind of came across something which I think you may have the answer for. To kind of summarize, I've been trying to use the mail() function to send messages to our clients regarding the invoices in question and it appears that those using outlook accounts are getting duplicate messages from within the same body template. I'm not sure how to proceed with resolving this.
– Ronnie
Nov 18 at 1:13




@EqualPro - Hey there, kind of came across something which I think you may have the answer for. To kind of summarize, I've been trying to use the mail() function to send messages to our clients regarding the invoices in question and it appears that those using outlook accounts are getting duplicate messages from within the same body template. I'm not sure how to proceed with resolving this.
– Ronnie
Nov 18 at 1:13


















draft saved

draft discarded




















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247790%2fq-insert-data-into-loop-statement%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Lugert, Oklahoma