Q: Insert data into loop statement
up vote
0
down vote
favorite
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
add a comment |
up vote
0
down vote
favorite
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
Where ismember_id
column ininvoices
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 insidewhile
.
– 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
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
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
php sql insert
edited Nov 11 at 10:36
asked Nov 11 at 10:23
Ronnie
32
32
Where ismember_id
column ininvoices
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 insidewhile
.
– 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
add a comment |
Where ismember_id
column ininvoices
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 insidewhile
.
– 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
add a comment |
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;
}
@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
add a comment |
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;
}
@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
add a comment |
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;
}
@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
add a comment |
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;
}
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;
}
answered Nov 11 at 11:06
EquaPro
1464
1464
@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
add a comment |
@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
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.
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.
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%2f53247790%2fq-insert-data-into-loop-statement%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
Where is
member_id
column ininvoices
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 insidewhile
.– 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