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));
}
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.
Comments