mysql data insert into table
I have two sql queries:
$query0=mysql_query("SELECT caseNumber FROM shipped_data WHERE palette='P0' AND shipInvoiceNumber='2011/229'");
$query1=mysql_query("SELECT caseNumber FROM shipped_data WHERE palette='P1' AND shipInvoiceNumber='2011/229'");
and using following php script to fetch da开发者_运维问答ta,
while($res0=mysql_fetch_array($query0))
{
$r0=$res0['caseNumber'];
$q0=mysql_query("INSERT INTO pallet (P00) VALUES ('$r0')")or die("Error");
}
while($res1=mysql_fetch_array($query1))
{
print $r1=$res1['caseNumber'];
$q1=mysql_query("INSERT INTO pallet (P01) VALUES ('$r1')")or die("Error");
}
This is the result:
First query inserts rows 1-10 of the data for coloumn1 The second query inserts rows 11-20 of the data for coloumn2.
What I need is rows 1-10 to be also inserted in column2, instead of rows 11-20
How can I do this?
I might help you looking at your problem from a different point of view. You can also perform your needs without having to loop through the records. You can execute the following SQL queries with PHP, or - if you have the ability - put this in a Stored Procedure, and call that.
The following SQL does the same as your PHP script.
INSERT INTO pallet (P00)
SELECT caseNumber
FROM shipped_data
WHERE palette='P0'
AND shipInvoiceNumber='2011/229';
INSERT INTO pallet (P01)
SELECT caseNumber
FROM shipped_data
WHERE palette='P1'
AND shipInvoiceNumber='2011/229';
精彩评论