How to execute a query number of times?

0

I'm doing a table in html and php, my problem is that I'm trying to execute a query ( insert ) 'n' number of times, I'm dealing with a for .

This is my code so far

<?php 

    for($ca=1; $ca<25; $ca++){
        $sqlc="insert into riesgos(no_riesgo,unidad_ad,seleccion_ad,descripcion_a,riesgod,nivel_de_dec,seleccion_c,otro,efectos,impacto_i,ocurrencia_i,controles_p,impacto_f,ocurrencia_f,estrategia,descripcion,no_factor,descripcion_f,clasificacion_f,tipo_f,no_control,descripcion_c,tipo_c,documentado,formalizado,aplica,efectivo) values('C','C','C','C','C','C','C','C','C','C','C','C','C','C','C','','','','','','','','','','','','')";
        $res = mysql_query($sqlc,Conectar::con());
    }

?>

To make it a little clearer and the functionality of inserting many 'C' , the C means that I will combine the cells in my table (this is done), they are 25 combinations , and those that do not have the 'C' I need to combine them only 5 times .

I hope you can help me!
Greetings.

    
asked by Donaldo Manzano 17.08.2018 в 17:44
source

1 answer

1

First I recommend instead of doing that, do a procedure where you receive all the data in JSON example

[{"nombre":"Pedro","apellido":"Fernandez"},{"nombre":"Jacinto","apellido":"Benavente"} ]

After this, in the procedure that you create in your BD manager, create the for and insert all this data. with this you will not have to make 25 connections to the database, you will have more control and security in the data.

If, on the other hand, you want to insert all the data just as you are doing, simply concatenate each of the inserts

 $sqlc .= "insert into riesgos(...)"

This will only make a connection to the BD and it will be much faster.

I hope I have helped resolve the doubt. GOOD DAY

    
answered by 22.08.2018 в 19:55