Di eBay ho preso solo alcune categorie, il progetto è tutt'altro
Comunque in definitiva io fare così:
Struttura Database:
Struttura database (ho omesso le tabelle non interessate)
Gestito da questa classe:
Codice PHP:
<?php
class features extends DB{
public $features = array();
public function newFeature($name,$id_lang){
$mysqli = $this->openDB();
$query = "INSERT INTO ".$this->features_t." ('id_feature') VALUES (NULL)";
$result = $mysqli->query($query);
if($result){
$id = $mysqli->insert_id;
$query = "INSERT INTO ".$this->features_lang_t." ('id_feature_lang','fk_feature','fk_lang','name')
VALUES (NULL,".$id.",".$id_lang.",'".$name."')";
$result = $mysqli->query($query);
if($result) return $id;
else return false;
}return false;
$this->closeDB($mysqli);
}
public function updateFeatureName($id_feat,$name,$id_lang){
$mysqli = $this->openDB();
$query = "SELECT * FROM ".$this->features_t.",".$this->features_lang_t." WHERE ".$this->features_t."id_feature = ".$this->features_lang_t.".fk_feature";
$result = $mysqli->query($query);
if($result){
$found = false;
while($data=$result->fetch_array()){
if($data['fk_lang'] == $id_lang){
$found = true;
$id = $data['id_feature_lang'];
}
}
if($found){
$query = "UPDATE ".$this->feature_lang_t." SET name = '".$name."' WHERE id_feature_lang = ".$id;
$result = $mysqli->query($query);
if($result) return true;
else return false;
}
}else return false;
$this->closeDB($mysqli);
}
public function getProductFeatures($id_prod,$id_lang){
$mysqli = $this->openDB();
$query = "SELECT ".$this->product_features_t.".fk_product AS id_prod,".$this->product_features_t.".fk_feature AS id_feature,
".$this->product_features_t.".feature_value AS feat_value,".$this->features_lang.".name AS feat_name,".$this->features_lang.".fk_lang AS feat_lang
FROM ".$this->product_features_t.",".$this->features_lang."
WHERE id_prod = ".$id_prod." AND id_feature = ".$this->features_lang.".fk_feature AND feat_lang = ".$id_lang."";
$result = $mysqli->query($query);
if($result)return $result;
else return false;
$this->closeDB($mysqli);
}
public function insertFeature($value,$id_prod,$id_lang,$id_feat=NULL,$name=NULL){
$mysqli = $this->openDB();
if(isset($id_feat)){
$result = $this->getProductFeatures($id_prod,$id_lang);
$found = false;
while($data = $result->fetch_array()){
if($data['id_feature'] == $id_feat){
$found = true;
}
}
if(!$found){
$query = "INSERT INTO ".$this->product_feat_t." ('id_product_feature','fk_product','fk_feature','feature_value')
VALUES (NULL,".$id_prod.",".$id_feat.",'".$value."');";
}else return false;
}else if($isset($name)){
$id_insert = $this->newFeature($name,$id_lang);
$query = "INSERT INTO ".$this->product_feat_t." ('id_product_feature','fk_product','fk_feature','feature_value')
VALUES (NULL,".$id_prod.",".$id_insert.",'".$value."');";
}else return false;
$result = $mysqli->query($query);
if($result) return true;
return false;
$this->closeDB($mysqli);
}
}
?>
La classe non è del tutto completa ma è il succo di sè, l'ho creata in 1 ora e mezza quindi ci saranno sicuramente degli errori e controlli omessi ed è il massimo che sono riuscito a fare.
Con questo metodo se ipotizzo di arrivare ad inserire 100 prodotti per ogni categoria, arrotondando a 2000 categorie, stimando 20 caratteristiche in media per ogni prodotto inserito, avrei la tabella "product_features" con 4.000.000 di record...non ho esperienza con numeri così grandi, ma spero non sia un problema, dato anche il fatto che i dati contenuti sono per lo più indici.