glicose Posted October 13, 2009 at 02:54 PM Report Share #291527 Posted October 13, 2009 at 02:54 PM Boas, tenho o seguinte problema. Tenho 2 arrays, um de tipo de telefone e o outro do número do telefone. Preciso pegar os valores desses 2 arrays e fazer um insert com os valores pra tabela. Só estou conseguindo passar o índice Quem puder ajudar agradeceria... Link to comment Share on other sites More sharing options...
scorch Posted October 13, 2009 at 02:59 PM Report Share #291528 Posted October 13, 2009 at 02:59 PM Dá mais detalhes. Podes mostrar o código? PS: Não respondo a perguntas por mensagem que podem ser respondidas no fórum. Link to comment Share on other sites More sharing options...
glicose Posted October 13, 2009 at 06:18 PM Author Report Share #291560 Posted October 13, 2009 at 06:18 PM Resolvi assim, não sei se tem alguma maneira mais fácil, mas deu certo Eu tinha 2 arrays, $this->telefones e $this->tipo_tel foreach ($this->telefones as $valor) { $tel[]=$valor; } foreach ($this->tipo_tel as $valor2) { $tipo[]=$valor2; } $tam=count($this->telefones); for ($i=0;$i<$tam;$i++) { mysql_query("INSERT INTO telefone_rep(telefone, tipo, id_rep) VALUES ('$tel[$i]', '$tipo[$i]', '$res[0]')"); } //Obs.: o $res[0] foi usado SELECT LAST_INSERT_ID() Mas muito obrigado amigo pela pronta disposição 👍 Caso tiver alguma maneira mais fácil, podem falar Obrigado APARTE: Não te esqueças de usar Geshi. 😛 Link to comment Share on other sites More sharing options...
jreis Posted October 13, 2009 at 06:33 PM Report Share #291563 Posted October 13, 2009 at 06:33 PM Podias usar um array multidimensioal, deste género: //... $this->tel[$j]['num'] = '12345678'; $this->tel[$j]['tipo'] = '1'; //... $tam = count($this->tel); for ($i = 0; $i < $tam; $i++) mysql_query("INSERT INTO telefone_rep(telefone, tipo, id_rep) VALUES ('" . $this->tel[$i]['num'] . "', '" .$this->tel[$i]['tipo']. "', '" . $res[0] . "'); Ou entao, mais simples ainda, assumindo números de telefone únicos (costuma ser o caso...) //... $this->tel[$num] = $tipo; //... foreach ($this->tel as $tel => $tipo) mysql_query("INSERT INTO telefone_rep(telefone, tipo, id_rep) VALUES ('" . $tel . "', '" .$tipo. "', '" . $res[0] . "'); APARTE: Não te esqueças de usar Geshi. 👍 "Pensa positivo: tudo pode piorar" Link to comment Share on other sites More sharing options...
glicose Posted October 13, 2009 at 07:42 PM Author Report Share #291572 Posted October 13, 2009 at 07:42 PM Valeu, vou testar, mas em todo caso podem fechar o tópico, que concerteza o problema está resolvido Abraços!!! 👍 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now