how can I insert in the table all the data of the query and not only take the first data that the query returns me?

0
$conexion= new mysqli($host, $usuario, $contraseña, $base);
if ($conexion -> connect_errno) 
{
    die("Fallo la conexion:(".$conexion -> mysqli_connect_errno().")".$conexion -> mysqli_connect_error());
}

$Query="call insertCons('$select')";
$resQuery = $conexion ->query($Query);

{
      $idSIM=$registroQuery['idSimulation'];
      $idSAP=$registroQuery['idSAP'];
      $Component=$registroQuery['Description'];
      $WC_Family=$registroQuery['WC_Family'];
      $STD=$registroQuery['FG_StdPack'];
      $RacksPerSAP=round($registroQuery['(products.DailyDemand/family.FG_StdPack)']*$DaysOfTheWeek);
      $TakttimeSAP=round($MinPWeek/$RacksPerSAP);
}

$conexion= new mysqli($host, $usuario, $contraseña, $base);
if ($conexion -> connect_errno) 
{
    die("Fallo la conexion:(".$conexion -> mysqli_connect_errno().")".$conexion -> mysqli_connect_error());
}

$FilledINConsumptions= "INSERT INTO consumptions (idSimulation, idSAP, Component, WC_Family, Dates, Quantity)
    VALUES ('$idSim', '$idSAP', '$Component', '$WC_Family', '$Minutes', '$STD')";

if ($conexion->query($FilledINConsumptions) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $FilledINConsumptions . "<br>" . $conexion->error;
} 
    
asked by Pepe 31.05.2018 в 23:34
source

1 answer

0

Probably your solution is to do the SQL side logic with INSERT INTO SELECT :

INSERT INTO table2
    SELECT * FROM table1
    WHERE condition;

Your case I think it would be something like:

"INSERT INTO consumptions " . $Query

Where your query would perform the surging and mulitplicacin / division operations.

If you do not have the possibility to do everything from SQL, you should iterate over each of the records and insert them into the table (non-functional example):

$FilledINConsumptions= "INSERT INTO consumptions (idSimulation, idSAP, Component, WC_Family, Dates, Quantity)
    VALUES ('$valores[0]'), ('$valores[1]'), ('$valores[2]'),..."
    
answered by 01.06.2018 в 00:51