par
tipi » 20 sept. 2009, 17:45
Bonjour,
Voici la construction de ma requête:
function obtenir_bijoux($parametre='')
{
// initialisation du tableau dans lequel on va récupérer les bijoux
$tab_bijoux = array();
$condition[] = array();
// nom des tables
$table_bijou = $this->name_table('bijoux');
$table_description = $this->name_table('description');
//$table_genreCollection = $this->name_table('genrecollection');
$table_collection = $this->name_table('collection');
$table_type = $this->name_table('type');
$table_matiere = $this->name_table('matiere');
$table_photos = $this->name_table('photos');
// valeurs par défaut
if(!is_array($parametre))
$parametre = array();
// valeur par défaut: langue
if (!isset($parametre['langue']))
$parametre['langue'] = $this->langue;
// valeur par défaut: produit actif
if (!isset($parametre['enLigne']))
$parametre['enLigne']= 'on';
// valeur par défaut des champs à sélectionner
if (!isset($parametre['champs']))
$parametre['champs'] = "*";
// valeur par défaut des tables à sélectionner
if (!isset($parametre['tables']))
$parametre['tables'] = "$table_bijou, $table_description, $table_photos, $table_matiere, $table_type ";
// condition: langue
if(strlen($parametre['langue']) == 2)
$condition[] = "and $table_description.langue like '".$parametre['langue']."'";
// conditions: collection
$condition[] = "and $table_bijou.numCollection = $table_collection.numCollection";
if(!eregi($table_collection, $parametre['tables']))
$parametre['tables'] .= ",$table_collection";
// condition: type
$condition[] = "and $table_bijou.numType = $table_type.numType";
// condition: matiere
$condition[] = "and $table_matiere.numMatiere = $table_bijou.numMatiere";
// condition: descriptif
$condition[] = "and $table_descriptif.numBijoux = $table_bijou.numBijoux";
if (isset($parametre['nomCollection']))
$condition[] = "and libCollection = $nomCollection";
// condition: produit actif
if(isset($parametre['actif']))
$condition = "and $table_bijou.enLigne = 'On'";
// conditions: photos
$condition[] = "and $table_photos.numBijoux = $table_bijou.numBijoux";
// requete sql
$commande = "select " .$parametre['champs']. " from " .$parametre['tables']. " where 1 ";
// requete sql: ajout des conditions
for($i = 0; $i < count($condition); $i++)
{
$commande .= ' ' .$condition[$i];
}
// plage de produit à récupérer pour limiter le nombre ou gérer les pages
if($parametre['nb_maxi'])
$commande .= " limit " .intval($parametre['nb_start']) . ',' .intval($parametre['nb_maxi']);
echo $commande;
Cependant lorsque j'affiche ma requête sauf un petit soucis(caractère gras):
select nomBijoux, nom_fichier, descriptionBijou from bijoux, description, photos,collection where 1 Array and description.langue like 'fr' and bijoux.numCollection = collection.numCollection and bijoux.numType = type.numType and matiere.numMatiere = bijoux.numMatiere and .numBijoux = bijoux.numBijoux and photos.numBijoux = bijoux.numBijoux limit 0,4 req_sql erreur:Erreur de syntaxe près de 'Array and description.langue like 'fr' and bijoux.numCollection = collection.num'
Merci pour votre aide
Bonjour,
Voici la construction de ma requête:
[php]function obtenir_bijoux($parametre='')
{
// initialisation du tableau dans lequel on va récupérer les bijoux
$tab_bijoux = array();
$condition[] = array();
// nom des tables
$table_bijou = $this->name_table('bijoux');
$table_description = $this->name_table('description');
//$table_genreCollection = $this->name_table('genrecollection');
$table_collection = $this->name_table('collection');
$table_type = $this->name_table('type');
$table_matiere = $this->name_table('matiere');
$table_photos = $this->name_table('photos');
// valeurs par défaut
if(!is_array($parametre))
$parametre = array();
// valeur par défaut: langue
if (!isset($parametre['langue']))
$parametre['langue'] = $this->langue;
// valeur par défaut: produit actif
if (!isset($parametre['enLigne']))
$parametre['enLigne']= 'on';
// valeur par défaut des champs à sélectionner
if (!isset($parametre['champs']))
$parametre['champs'] = "*";
// valeur par défaut des tables à sélectionner
if (!isset($parametre['tables']))
$parametre['tables'] = "$table_bijou, $table_description, $table_photos, $table_matiere, $table_type ";
// condition: langue
if(strlen($parametre['langue']) == 2)
$condition[] = "and $table_description.langue like '".$parametre['langue']."'";
// conditions: collection
$condition[] = "and $table_bijou.numCollection = $table_collection.numCollection";
if(!eregi($table_collection, $parametre['tables']))
$parametre['tables'] .= ",$table_collection";
// condition: type
$condition[] = "and $table_bijou.numType = $table_type.numType";
// condition: matiere
$condition[] = "and $table_matiere.numMatiere = $table_bijou.numMatiere";
// condition: descriptif
$condition[] = "and $table_descriptif.numBijoux = $table_bijou.numBijoux";
if (isset($parametre['nomCollection']))
$condition[] = "and libCollection = $nomCollection";
// condition: produit actif
if(isset($parametre['actif']))
$condition = "and $table_bijou.enLigne = 'On'";
// conditions: photos
$condition[] = "and $table_photos.numBijoux = $table_bijou.numBijoux";
// requete sql
$commande = "select " .$parametre['champs']. " from " .$parametre['tables']. " where 1 ";
// requete sql: ajout des conditions
for($i = 0; $i < count($condition); $i++)
{
$commande .= ' ' .$condition[$i];
}
// plage de produit à récupérer pour limiter le nombre ou gérer les pages
if($parametre['nb_maxi'])
$commande .= " limit " .intval($parametre['nb_start']) . ',' .intval($parametre['nb_maxi']);
echo $commande;[/php]
Cependant lorsque j'affiche ma requête sauf un petit soucis(caractère gras):
[quote]select nomBijoux, nom_fichier, descriptionBijou from bijoux, description, photos,collection where 1 [b]Array[/b] and description.langue like 'fr' and bijoux.numCollection = collection.numCollection and bijoux.numType = type.numType and matiere.numMatiere = bijoux.numMatiere and .numBijoux = bijoux.numBijoux and photos.numBijoux = bijoux.numBijoux limit 0,4 req_sql erreur:Erreur de syntaxe près de 'Array and description.langue like 'fr' and bijoux.numCollection = collection.num' [/quote]
Merci pour votre aide