|
|
|
|
Bonjour je suis completement perdu dans mon code,mon probleme c'est juste de la logique,l'ennui c'est qu'a force de travailler sur ce code je deviens completement gaga
En fait ce que je cherche a faire depuis le debut c'est :
WHERE (pr.PerfName="Valeur choisie")AND(pr.TypePerf="Performer" OR pr.TypePerf="Panel" OR pr.TypePerf="Workshop") AND (pr.PerfCodeName="Valeur choisie" )AND (pf.Date="5/26/2006" OR pf.Date="5/27/2006" OR pf.Date="5/28/2006" OR pf.Date="5/29/2006")AND (pf.Start="Valeur choisie") AND (pf.End="valeur choisie") AND (pl.Stage="Valeur choisie") AND (pl.LocStage="Outdoor" OR pl.LocStage="Indoor")
avec le code suivant mais je ne vois vraiment pas comment faire(j'ai esseye mille et une combinaisons de parentheses),pouvez vous m'aider s'il vous plait?:
<?php
array('Performer', 'Panel','Workshop');
array('5/26/2006','5/27/2006','5/28/2006','5/29/2006');
array('Indoor', 'Outdoor');
$where = 'WHERE (';
$and=false; //au départ aucun type d'information n'a été détécté
if(ISSET($_POST['perfname'])&&$_POST['perfname']!='')
{$where = $where.' (pr.PerfName="'.$_POST['perfname'].'"';
$and=true;}
if(isset($_POST['typeperf']) AND is_array($_POST['typeperf']))
{
foreach($_POST['typeperf'] AS $valeur)
{
if(ISSET($_POST['typeperf'])&&$_POST['typeperf']!='')
{if($and) $where = $where.' OR ';
$where = $where.' pr.TypePerf="'.$valeur.'"';
$and=true;}}
$where = $where . ') '; }
if(ISSET($_POST['perfcodename'])&&$_POST['perfcodename']!='')
{if($and) $where = $where.' AND ';
$where = $where.' pr.PerfCodeName="'.$_POST['perfcodename'].'"';
$and=true;}
if(isset($_POST['date']) AND is_array($_POST['date']))
{
foreach($_POST['date'] AS $valeur2)
{
if(ISSET($_POST['date'])&&$_POST['date']!='')
{if($and) $where = $where.' OR ';
$where = $where.' pf.Date="'.$valeur2.'"';
$and=true;}}
$where = $where . ') '; }
if(ISSET($_POST['start'])&&$_POST['start']!='')
{if($and) $where = $where.' AND ';
$where = $where.' pf.Start="'.$_POST['start'].'"';
$and=true;}
if(ISSET($_POST['end'])&&$_POST['end']!='')
{if($and) $where = $where.' AND ';
$where = $where.' pf.End="'.$_POST['end'].'"';
$and=true;}
if(ISSET($_POST['stage'])&&$_POST['stage']!='')
{if($and) $where = $where.' AND ';
$where = $where.' pl.Stage="'.$_POST['stage'].'"';
$and=true;}
if(isset($_POST['locstage']) AND is_array($_POST['locstage']))
{
foreach($_POST['locstage'] AS $valeur3)
{
if(ISSET($_POST['locstage'])&&$_POST['locstage']!='')
{if($and) $where = $where.' OR ';
$where = $where.' pl.LocStage="'.$valeur3.'"';
$and=true;}}
$where = $where . ') '; }
if($and!=true) $where = $where.' 1';
$q = 'SELECT pr.*,
pf.*,
pl.*
FROM performer AS pr
INNER JOIN performance AS pf ON pr.IDPerf=pf.IDPerf
INNER JOIN place AS pl ON pl.CodeStage=pf.CodeStage '.$where;
echo "$q";
?>
Bonjour,
|
Excuse moi mais j'ai finalement resolu mon probleme grace a d'autres internautes,je te remercie pour le mal que tu t'es donne,je copie le code en compensation,je suis vraiment desole je trouve degueulasse de t'avoir fait travailler pour rien:
<?php
// Début du code proprement dit !!
array('Performer', 'Panel','Workshop');
array('5/26/2006','5/27/2006','5/28/2006','5/29/2006');
array('Indoor', 'Outdoor');
$where = 'WHERE ';
$and=false; //au départ aucun type d'information n'a été détécté
if(ISSET($_POST['perfname'])&&$_POST['perfname']!='')
{
$where .= ' pr.PerfName="'.$_POST['perfname'].'"';
$and=true;
}
if(isset($_POST['typeperf']))
{
if (is_array($_POST['typeperf']))
{
$premier = true; // A METTRE DANS LES TROIS !!
$nonvide = false;
foreach($_POST['typeperf'] AS $valeur)
{
if ($valeur != "")
{
if (!$nonvide)
{
if($and) $where .= ' AND '; //RAJOUT !!!
$where .= ' ( ';
$nonvide=true;
}
if(!$premier)// MODIF
{// MODIF
$where .= ' OR '; // MODIF
}// MODIF
else// MODIF
{// MODIF
$premier=false; // MODIF
}// MODIF
$where .= ' pr.TypePerf="'.$valeur.'"';
$and=true;
}
}
if ($nonvide)
{
$where .= ' ) ';
}
}
}
if(ISSET($_POST['perfcodename']))
{
if ($_POST['perfcodename']!='')
{
if($and) $where .= ' AND ';
$where .= ' ( ';
$where .= ' pr.PerfCodeName="'.$_POST['perfcodename'].'"';
$where .= ' ) ';
$and=true;
}
}
if(isset($_POST['date']))
{
if (is_array($_POST['date']))
{
$premier = true; // A METTRE DANS LES TROIS !!
$nonvide = false;
foreach($_POST['date'] AS $valeur)
{
if ($valeur != "")
{
if (!$nonvide)
{
if($and) $where .= ' AND '; //RAJOUT !!!
$where .= ' ( ';
$nonvide=true;
}
if(!$premier)// MODIF
{// MODIF
$where .= ' OR '; // MODIF
}// MODIF
else// MODIF
{// MODIF
$premier=false; // MODIF
}// MODIF
$where .= ' pf.Date="'.$valeur.'"';
$and=true;
}
}
if ($nonvide)
{
$where .= ' ) ';
}
}
}
if(ISSET($_POST['start']))
{
if ($_POST['start']!='')
{
if($and) $where .= ' AND ';
$where .= ' ( ';
$where .= ' pf.Start="'.$_POST['start'].'"'; //VERIFIER !!!!!!!!!!
$where .= ' ) ';
$and=true;
}
}
if(ISSET($_POST['end']))
{
if ($_POST['end']!='')
{
if($and) $where .= ' AND ';
$where .= ' ( ';
$where .= ' pf.End="'.$_POST['end'].'"'; //VERIFIER !!!!!!!!!!
$where .= ' ) ';
$and=true;
}
}
if(ISSET($_POST['stage']))
{
if ($_POST['stage']!='')
{
if($and) $where .= ' AND ';
$where .= ' ( ';
$where .= ' pl.Stage="'.$_POST['stage'].'"'; //VERIFIER !!!!!!!!!!
$where .= ' ) ';
$and=true;
}
}
if(isset($_POST['locstage']))
{
if (is_array($_POST['locstage']))
{
$premier = true; // A METTRE DANS LES TROIS !!
$nonvide = false;
foreach($_POST['locstage'] AS $valeur)
{
if ($valeur != "")
{
if (!$nonvide)
{
if($and) $where .= ' AND '; //RAJOUT !!!
$where .= ' ( ';
$nonvide=true;
}
if(!$premier)// MODIF
{// MODIF
$where .= ' OR '; // MODIF
}// MODIF
else// MODIF
{// MODIF
$premier=false; // MODIF
}// MODIF
$where .= ' pl.LocStage="'.$valeur.'"';
$and=true;
}
}
if ($nonvide)
{
$where .= ' ) ';
}
}
}
if($and!=true) $where .= ' 1';
$q = 'SELECT pr.*,
pf.*,
pl.*
FROM performer AS pr
INNER JOIN performance AS pf ON pr.IDPerf=pf.IDPerf
INNER JOIN place AS pl ON pl.CodeStage=pf.CodeStage '.$where;
echo "$q";
|