Jump to content

[RESOLVIDO] 2 arrays para uma tabela


glicose
 Share

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.