0
I have the following PHP:
# Prospect
$sql_prospect = "SELECT * FROM interessados LIMIT 100";
$exe_prospect = mysqli_query($link, $sql_prospect);
$i = 0;
while($res_prospect=mysqli_fetch_array($exe_prospect, MYSQLI_ASSOC)){
$prospect[$i]['uni_id'] = $res_prospect['int_cod_unidade'];
$prospect[$i]['cur_id'] = $res_prospect['int_cod_curso'];
$prospect[$i]['usu_id'] = $res_prospect['int_cod_consultora'];
$prospect[$i]['cam_id'] = $res_prospect['int_cod_campanha'];
$prospect[$i]['pro_id_origem'] = $res_prospect['int_cod_origem'];
$prospect[$i]['pro_nome'] = $res_prospect['int_nome'];
$prospect[$i]['pro_telefone'] = $res_prospect['int_telefone'];
$prospect[$i]['pro_whatsapp'] = $res_prospect['int_whatsapp'];
$prospect[$i]['pro_endereco_cep'] = $res_prospect['int_endereco_cep'];
$prospect[$i]['pro_endereco'] = $res_prospect['int_endereco'];
$prospect[$i]['pro_endereco_estado'] = $res_prospect['int_endereco_estado'];
$prospect[$i]['pro_endereco_cidade'] = $res_prospect['int_endereco_cidade'];
$prospect[$i]['pro_email'] = $res_prospect['int_email'];
$prospect[$i]['pro_data'] = $res_prospect['int_data'];
$prospect[$i]['pro_data_nascimento'] = $res_prospect['int_data_nascimento'];
$prospect[$i]['pro_observacao'] = $res_prospect['int_observacao'];
$prospect[$i]['pro_status'] = $res_prospect['int_status'];
$i++;
}
In such a way that, $prospect,
all arrays are assigned, as shown above.
What would be the right way to enter in the database? Without me having to do "insert into tabela (campo1, campo2, campo3) values (campo1, campo2, campo3).."
I’d like to do something like that: INSERT INTO tabela (todos_os_campos) VALUE (todos_os_campos)
, maybe with some kind of implode?
With the function
array_keys
you can get the list of indexes and with thearray_values
values. Just convert both to string with thejoin
(orimplode
) and build SQL.– Woss
It is a solution @Andersoncarloswoss, but my return would look like this: INSERT INTO Prospect (uni_id,cur_id,usu_id,cam_id,pro_id_origem,pro_nome,pro_telefone,pro_whatsapp,pro_endereco_cep,pro_endereco,pro_endereco_estado,pro_endereco_cidade,pro_email,pro_data,pro_data_nascimento,pro_observacao,pro_status) VALUES (1,24,0,2,63,Leonardo,,(32) 9912-15056,,,0,0,,2016-09-02 20:13:29,0000-00-00,51), which would error the insert.
– Sr. André Baill
Put everything in quotes then. Whatever number the bank solves.
– Francisco