Salve ho questo codice:

Codice PHP:
$id_tipo = array(); 
$q "SELECT * FROM products_options WHERE products_options_name = '".$_POST['TipoVariante1']."'"
$s mysql_query($q) or die (mysql_error()); 
while (
$row mysql_fetch_array($s)){     
$id_tipo[] = $row['products_options_id']; 
}  
$q "SELECT * FROM products_options_values WHERE products_options_values_name = '".$_POST['Variante1']."'"
$s mysql_query($q) or die (mysql_error()); 
while (
$row mysql_fetch_array($s)){     
$id_var $row['products_options_values_id'];
 }  
$q "SELECT * FROM products_options_values_to_products_options WHERE products_options_id = '$id_tipo'"
$s mysql_query($q) or die (mysql_error());
 while (
$row mysql_fetch_array($s)){     
$id_p[] = $row['products_options_id']; 
}  
$array explode("," ,$_POST['Variante1']);  
$var1 count($array);
 
$res1 false
for(
$i=0;$i<$var1;$i++) 

//qui verificare se qualche valore esiste in $id_tipo che sia uguale a $id_p
if ($id_tipo[$i]==$id_p[$i])    
 { 
$res1=true;     

}  
if(
$res1 == false
{    
$q "SELECT * FROM products_options WHERE products_options_name = '".$_POST['TipoVariante1']."'"
$s mysql_query($q) or die (mysql_error()); 
while (
$row mysql_fetch_array($s)){    
 
$id_tipo $row['products_options_id']; 
}  
$q "SELECT * FROM products_options_values WHERE products_options_values_name = '".$_POST['Variante1']."'";
$s mysql_query($q) or die (mysql_error()); 
while (
$row mysql_fetch_array($s)){     
$id_var $row['products_options_values_id']; 
}  
$query "INSERT INTO products_options_values_to_products_options 
(products_options_id, products_options_values_id) VALUES 
('
$id_tipo', '$id_var')"
$insert mysql_query($query);    
if(!
$insert) die(mysql_error());  

Questo codice mi permette di prelevare ed inserire dati in un'altra tabella, tante volte quanti sono i valori contenuti in $_POST['Variante1'], però il mio problema è che voglio vedere se nella tabella products_options_values_to_products_options già esiste qualche valore contenuto nell'array, altrimenti deve scriverlo, con questo codice, anche se già presente un valore nel database, mi riscrive tutto.

Come posso fare?

Grazie