5
I have 2 PHP arrays that come from a form $_POST['qtd']
and $_POST['ing']
:
array(2) { [0]=> string(1) "1" [1]=> string(1) "2" }
array(2) { [0]=> string(1) "a" [1]=> string(1) "b" }
It has, somehow, to join them into a variable that was like this?
$variavel = "(1,'a'), (2,'b')";
With that I’ll make one INSERT
in the MYSQL table that should look like this:
INSERT INTO tabela (qtd, ing) VALUES (1,'a'), (2,'b');
Will generate an sql with this? at least has face.
– rray
And parentheses are part of string? could format exactly how accurate the result?
– Woss
this, I will do a mysql Insert, will look like this: INSERT INTO table (Qtd, ing) VALUES (1,a), (2,b);
– Leandro Marzullo
In the title you say you want to generate a string but the expected result is an array. You can clarify or edit the question?
– fernandosavio
yeah, I think the title was not clear mt, I will edit, but what I need is this, take the 2 arrays, to make an input in mysql
– Leandro Marzullo
So your problem is another, not just joining in a string. It is likely that @rray is already formulating an answer, but it is more advisable to use
prepared statements
for safety and because it is more practical. Are you using which extension to make the connection? PDO, mysqli or any other?– fernandosavio