looping mysql query to get multiple rows of data from a table and insert into another table

user3620142

I am working on a small project and is having some issues with looping MySQL insert. I currently have 2 database tables. I am fetching information from one to another.

table with data:

$q = "SELECT * FROM HARDWARE WHERE ID_2=".$db->qstr(20);
$rss = $db->execute($q);
$re2=$rss->GetArray();

so I am getting the array of data fine.

inserting the data only if the id is {20} Currently I have 2 rows with ID_2 = 20 but it is only inserting one row not both. here is my insert query.

$sql = "INSERT INTO PARTS SET
          IN_ID     =". $db->qstr($in_id).",
      ER_ID     =". $db->qstr( $er_id).",
      ITEM      =". $db->qstr( $re2[0]['ITEM']   ).",
      NAME      =". $db->qstr( $re2[0]['NAME']   );

it inserts the data fine, just one row not multiple rows. any suggestions?

Thanks.

Marius.C

Insert your query in a loop

foreach ($re2 as $r): $sql = "INSERT INTO PARTS SET IN_ID =". $db->qstr($in_id).", ER_ID =". $db->qstr( $er_id).", ITEM =". $db->qstr( $r['ITEM'] ).", NAME =". $db->qstr( $r['NAME'] ); endforeach;

or use multiple inserts Inserting multiple rows in mysql

both should be fine at what you have there.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

insert multiple rows mysql from another table

From Dev

How to insert multiple rows from a table to another table based on date condition (PHP-MySQL-Query)?

From Dev

Insert multiple rows with single a query from one table into another in Oracle

From Dev

MySQL - Insert table data from another table

From Dev

MySQL - Insert table data from another table

From Dev

Insert multiple rows from select into another table

From Dev

Insert multiple rows into a MySQL database from a table

From Dev

Mysql query insert from another table

From Dev

Mysql insert into with multiple id from another table

From Dev

Insert (multiple) new rows into a table from another table using a subquery?

From Dev

MYSQL - UPDATE multiple rows from another table

From Dev

MySQL query - single row in one table with multiple rows in another table

From Dev

MySQL insert into column data from another table

From Dev

Insert Data From One Table To Another - MySQL

From Dev

Insert new rows into table but copy data from another row in the table

From Dev

Mysql query to get rows of a table as columns of another, with column names from third table

From Dev

Select multiple columns from a table and insert data into another table in a different database in PHP-MySQL

From Dev

Update MYSQL Table from multiple rows in another table

From Dev

select multiple column from one table and insert into another as rows

From Dev

SQL insert multiple rows from single field in another table

From Dev

INSERT rows multiple times based on a column value from another table

From Dev

Insert rows into a table from another two tables separately in mysql

From Dev

Insert Data from one table to another leaving the already existing rows

From Dev

Select from multiple tables, insert into another table Oracle SQL query

From Dev

Hibernate HQL query get data from table associated with another table

From Dev

MySql Retrieving Data from multiple Tables then Insert limited values In another table

From Dev

SQL insert data into a table from another table

From Dev

SQL insert data into a table from another table

From Dev

Multiple insert in MySQL table from PHP table

Related Related

  1. 1

    insert multiple rows mysql from another table

  2. 2

    How to insert multiple rows from a table to another table based on date condition (PHP-MySQL-Query)?

  3. 3

    Insert multiple rows with single a query from one table into another in Oracle

  4. 4

    MySQL - Insert table data from another table

  5. 5

    MySQL - Insert table data from another table

  6. 6

    Insert multiple rows from select into another table

  7. 7

    Insert multiple rows into a MySQL database from a table

  8. 8

    Mysql query insert from another table

  9. 9

    Mysql insert into with multiple id from another table

  10. 10

    Insert (multiple) new rows into a table from another table using a subquery?

  11. 11

    MYSQL - UPDATE multiple rows from another table

  12. 12

    MySQL query - single row in one table with multiple rows in another table

  13. 13

    MySQL insert into column data from another table

  14. 14

    Insert Data From One Table To Another - MySQL

  15. 15

    Insert new rows into table but copy data from another row in the table

  16. 16

    Mysql query to get rows of a table as columns of another, with column names from third table

  17. 17

    Select multiple columns from a table and insert data into another table in a different database in PHP-MySQL

  18. 18

    Update MYSQL Table from multiple rows in another table

  19. 19

    select multiple column from one table and insert into another as rows

  20. 20

    SQL insert multiple rows from single field in another table

  21. 21

    INSERT rows multiple times based on a column value from another table

  22. 22

    Insert rows into a table from another two tables separately in mysql

  23. 23

    Insert Data from one table to another leaving the already existing rows

  24. 24

    Select from multiple tables, insert into another table Oracle SQL query

  25. 25

    Hibernate HQL query get data from table associated with another table

  26. 26

    MySql Retrieving Data from multiple Tables then Insert limited values In another table

  27. 27

    SQL insert data into a table from another table

  28. 28

    SQL insert data into a table from another table

  29. 29

    Multiple insert in MySQL table from PHP table

HotTag

Archive