简体   繁体   English

如何在mysql中使用php插入动态输入值将一张表同时复制到另一张表

[英]How to insert dynamic input values copy one table to another table at the same time in mysql using php

需要同时将一张表复制到另一张表如何使用PHP在MySQL中插入动态输入值?

$srl="INSERT INTO sales (itemname,itemquantity,price,noofproduct,total)SELECT itemname,itemquantity,price FROM hsale VALUES('".$rowcount."','".$sum."')";

First get data from hsale table首先从hsale表中获取数据

$hsale_data = $conexion->query("SELECT itemname,itemquantity,price FROM hsale");

Second travel the data array adding its values to a insert into query第二次遍历数据数组,将其值添加到插入到查询中

$query = "INSERT INTO sales (itemname,itemquantity,price) VALUES ()";
while($row = mysqli_fetch_assoc($hsale_data) ){
    $query .= ",( '$row[`itemname`]',$row[`itemquantity`] ,$row[`price`] )";
}

Third send the query to database第三次将查询发送到数据库

// Print query to know if its syntaxis is alright
echo "<pre>";
echo $query;
echo "</pre>";

// Send to database
$conexion->query($query);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从一个表数据复制列到另一表并在mysql中同时插入更多列? - how to copy column from one table data to another table and insert more columns same time in mysql? 如何在PHP和MySQL中将几条记录从一台服务器上的表复制到另一台服务器上具有相同结构的表? - How to copy few records from a table on one server to the table with same structure on another server in PHP and MySQL? PHP MySQL使用where子句INSERT来自另一个表的数据,并将唯一值插入到相同的行中 - PHP MySQL INSERT data from another table using the where clause and insert unique values to the same rows 在使用 php 同时按 id 在 mysql 中删除之前,在另一个表中插入旧数据 - insert old data on another table before deleting in mysql using php at the same time by id 如何在PHPMyAdmin MySQL的同一表中将值从一行复制到另一行 - How to copy values from one row to another in the same table in PHPMyAdmin MySQL MYSQL在不同的表PHP中插入相同的值 - MYSQL Insert the same values in different table PHP PHP MYSQL从另一个表插入一个表 - PHP MYSQL Insert Into one table from another 使用PHP和MySQL如何使用另一个表中的某些字段值填充一个表 - Using PHP and MySQL how do I populate one table using some field values from another table 如何将多个php数组值插入到同一个表的mysql中? - how to insert multiple php array values into mysql for the same table? 如何使用php将动态文本框值插入相同ID的数据库表中? - How can i insert dynamic textbox values into database table on same ID using php?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM