m_abdlmalek
Messages postés21Date d'inscriptionmardi 16 janvier 2007StatutMembreDernière intervention 5 septembre 2011
-
22 juin 2011 à 20:21
m_abdlmalek
Messages postés21Date d'inscriptionmardi 16 janvier 2007StatutMembreDernière intervention 5 septembre 2011
-
25 juin 2011 à 17:06
Bonjour,
Svp s'il y a un expert en PHP MYSQL, je souhaiterais faire valider cette requête c'est bizarre elle ne me donne aucun résultat.
Normalement le principe est de récupérer des infos dans une 1ere table et les rechercher dans une 2ème :
<?php
// requête qui va charger les éléments à rechercher dans la base :
$sql006='SELECT id, Adresse_messagerie, champ1, champ2, champ3, champ4, champ5, champ6, champ7, champ8 FROM table1 WHERE 1=1';
$req006=mysql_query($sql006);
$data006=mysql_fetch_array($req006) or die('Erreur SQL !
'.$sql006.'
'.mysql_error());
// la requête qui récupère les données de la 1ere table et va compter les lignes vérifiant les critères dans la 2ème :
$sql008="SELECT count(*) FROM table2 WHERE
IF('".$data006['Champ1']."'!='', Champ1 like '%".$data006['Champ1']."%','')
and IF('".$data006['Champ2']."'!='', Champ2='".mysql_escape_string($data006['Champ2'])."','')
and IF('".$data006['Champ3']."'!='', Champ3 like '%".$data006['Champ3']."%','')
and IF('".$data006['champ4']."'!='', champ4 ='".mysql_escape_string($data006['champ4'])."','')
and IF('".$data006['champ5']."'!='', champ5='".mysql_escape_string($data006['champ5'])."','')
and IF('".$data006['champ6']."'!='', champ6 like '%".$data006['champ6']."%','')
and IF('".$data006['champ7']."'!='', champ7 like '%".$data006['champ7']."%','')
and IF('".$data006['champ8']."'!='', champ8 like '%".$data006['champ8']."%','')";
// exécution
$req008=mysql_query($sql008) or die('Erreur SQL !
'.$sql008.'
'.mysql_error());
$data008=mysql_fetch_array($req008);
echo $data008[0].'
';
// la requête qui recherche les données dans la 2eme table :
$sql007="SELECT id, Adresse_messagerie, champ1, champ2, champ3, champ4, champ5, champ6, champ7, champ8 WHERE
IF('".$data006['Champ1']."'!='', Champ1 like '%".$data006['Champ1']."%','')
and IF('".$data006['Champ2']."'!='', Champ2='".mysql_escape_string($data006['Champ2'])."','')
and IF('".$data006['Champ3']."'!='', Champ3 like '%".$data006['Champ3']."%','')
and IF('".$data006['champ4']."'!='', champ4 ='".mysql_escape_string($data006['champ4'])."','')
and IF('".$data006['champ5']."'!='', champ5='".mysql_escape_string($data006['champ5'])."','')
and IF('".$data006['champ6']."'!='', champ6 like '%".$data006['champ6']."%','')
and IF('".$data006['champ7']."'!='', champ7 like '%".$data006['champ7']."%','')
and IF('".$data006['champ8']."'!='', champ8 like '%".$data006['champ8']."%','')";
// execution
$req007=mysql_query($sql007) or die('Erreur SQL !
'.$sql007.'
'.mysql_error());
?>