php pdo select multiple rows and insert to other table with LIMIT

jin

i have 2 tables equip_copy(copyID, equipment_id) and insert it to table

mre_copy (mreID,copyID,equipment_id)

I have tried this Select query but doesnt move. Please anyone can help me?

$display = $con->query("SELECT copyID,equipmentID
                         FROM equip_copy
                         WHERE equipmentID= :eid
                         ORDER BY copyID DESC 
                         LIMIT :elimit");

$display->execute(array("eid" => $id, "elimit"=>$request));

foreach($display as $row){

        $newCID = $row['copyID']; 
        $newEID = $row['equipmentID'];

        $sql_table = "INSERT INTO mre_copy(mreID,equipmentID,copyID) values(?,?,?)";
        $stmt = $con->prepare($sql_table);
        $stmt->execute(array($mreID,$newEID,$newCID));
}

enter image description here

Gordon Linoff

Use insert . . . select. I think this is what you want to do

INSERT INTO mre_copy (mreID, equipmentID, copyID) 
    SELECT :mreID, copyID, equipmentID
    FROM equip_copy
    WHERE equipmentID = :eid
    ORDER BY copyID DESC 
    LIMIT :elimit;

I'm not sure where mreID comes from. If it is auto-incremented, then just leave it out of the INSERT altogether.

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 using PHP PDO

From Dev

how to Insert multiple arrays with multiple rows into MySQL using PHP PDO

From Dev

Insert multiple rows from select into another table

From Dev

What is the best way to insert multiple rows in PHP PDO MYSQL?

From Dev

PHP PDO SELECT LIMIT issue

From Dev

PHP PDO Multiple image INSERT

From Dev

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

From Dev

Insert-Select for single result of multiple rows in same table

From Dev

SELECT Columns FROM other Table but Should Return Multiple Rows

From Dev

Select rows from a table based on results from two other tables in mySQL using PDO

From Dev

How insert multiple rows in mysql table with php array?

From Dev

INSERT multiple rows with SELECT and an array

From Dev

Postgresql Insert select with multiple rows

From Dev

PHP PDO Multiple Table join

From Dev

Insert multiple rows in table with a join

From Dev

Selecting multiple rows in a Select statement using PDO

From Dev

mysql insert with select query to insert multiple rows

From Dev

php select entire table and set variables from multiple rows by id

From Dev

PHP, PDO, MySQL - Multiple INSERT vulnerable to injection?

From Dev

Insert multiple <select> options into multiple rows

From Dev

PHP PDO counting all table rows in Database

From Dev

PHP PDO counting all table rows in Database

From Dev

Decrement column value on multiple rows with PHP and PDO

From Dev

how to select one row from one table and multiple rows from other table using joins in mysql,

From Dev

Insert multiple rows from other table - "Subquery returns more than 1 row"

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 into database (PDO) [Items separated by commas]

From Dev

Select rows conditionally and insert into another table conditionally

From Dev

SQLITE Insert Multiple Rows Using Select as Value

Related Related

  1. 1

    Insert multiple rows using PHP PDO

  2. 2

    how to Insert multiple arrays with multiple rows into MySQL using PHP PDO

  3. 3

    Insert multiple rows from select into another table

  4. 4

    What is the best way to insert multiple rows in PHP PDO MYSQL?

  5. 5

    PHP PDO SELECT LIMIT issue

  6. 6

    PHP PDO Multiple image INSERT

  7. 7

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

  8. 8

    Insert-Select for single result of multiple rows in same table

  9. 9

    SELECT Columns FROM other Table but Should Return Multiple Rows

  10. 10

    Select rows from a table based on results from two other tables in mySQL using PDO

  11. 11

    How insert multiple rows in mysql table with php array?

  12. 12

    INSERT multiple rows with SELECT and an array

  13. 13

    Postgresql Insert select with multiple rows

  14. 14

    PHP PDO Multiple Table join

  15. 15

    Insert multiple rows in table with a join

  16. 16

    Selecting multiple rows in a Select statement using PDO

  17. 17

    mysql insert with select query to insert multiple rows

  18. 18

    php select entire table and set variables from multiple rows by id

  19. 19

    PHP, PDO, MySQL - Multiple INSERT vulnerable to injection?

  20. 20

    Insert multiple <select> options into multiple rows

  21. 21

    PHP PDO counting all table rows in Database

  22. 22

    PHP PDO counting all table rows in Database

  23. 23

    Decrement column value on multiple rows with PHP and PDO

  24. 24

    how to select one row from one table and multiple rows from other table using joins in mysql,

  25. 25

    Insert multiple rows from other table - "Subquery returns more than 1 row"

  26. 26

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

  27. 27

    Insert multiple rows into database (PDO) [Items separated by commas]

  28. 28

    Select rows conditionally and insert into another table conditionally

  29. 29

    SQLITE Insert Multiple Rows Using Select as Value

HotTag

Archive