Probleme de logique avec des "OR" "
Résolu
nanor21
Messages postés
16
Date d'inscription
Statut
Membre
Dernière intervention
-
ollie314 Messages postés 145 Date d'inscription Statut Membre Dernière intervention -
ollie314 Messages postés 145 Date d'inscription Statut Membre Dernière intervention -
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?:
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"; ?>
A voir également:
- Probleme de logique avec des "OR" "
- Or - Guide
- Livre d'or hiwit - Forum Webmastering
- X64 or x86 ✓ - Forum Windows
- Eql test logique - Forum Programmation
- C'est quoi x86 et x64 ✓ - Forum Windows
3 réponses
Bonjour,
Essaye cela, je ne sais pas si ça va marcher, je n'ai pas modifier grand chose...
<?php
array('Performer', 'Panel','Workshop');
array('5/26/2006','5/27/2006','5/28/2006','5/29/2006');
array('Indoor', 'Outdoor');
$where = 'WHERE (';
unset($exp); // on libère la variable au cas où elle existe et possède une valeur
if( ISSET($_POST['perfname']) && $_POST['perfname'] != '' )
{
$exp = ' (pr.PerfName="'.$_POST['perfname'].'"';
}
$where .= $exp;
if($exp){$exp = '';}
if( isset($_POST['typeperf']) AND is_array($_POST['typeperf']) )
{
foreach($_POST['typeperf'] AS $valeur)
{
if( ISSET($_POST['typeperf']) && $_POST['typeperf'] != '' )
{
if($exp) $exp .= ' OR ';
$exp .= ' pr.TypePerf="'.$valeur.'"';
}
}
$where .= $exp . ') ';
}
if($exp){$exp = '';}
if( ISSET($_POST['perfcodename']) && $_POST['perfcodename'] != '' )
{
if($exp) $exp .= ' AND ';
$exp .= ' pr.PerfCodeName="'.$_POST['perfcodename'].'"';
}
$where .= $exp;
if($exp){$exp='');
if( isset($_POST['date']) AND is_array($_POST['date']) )
{
foreach($_POST['date'] AS $valeur2)
{
if(ISSET($_POST['date']) && $_POST['date'] != '' )
{
if($exp) $exp .= ' OR ';
$exp .=' pf.Date="'.$valeur2.'"';
}
}
$where .= $exp . ') ';
}
if($exp){$exp='');
if(ISSET($_POST['start']) && $_POST['start'] != '' )
{
if($exp) $exp .= ' AND ';
$exp .= ' pf.Start="'.$_POST['start'].'"';
}
$where .= $exp;
if($exp){$exp='');
if( ISSET($_POST['end']) && $_POST['end'] != '' )
{
if($exp) $exp .= ' AND ';
$exp = ' pf.End="'.$_POST['end'].'"';
}
$where .= $exp;
if($exp){$exp='');
if( ISSET($_POST['stage']) && $_POST['stage'] != '' )
{
if($exp) $exp .= ' AND ';
$exp .= ' pl.Stage="'.$_POST['stage'].'"';
}
$where .= $exp;
if($exp){$exp='');
if(isset($_POST['locstage']) AND is_array($_POST['locstage']))
{
foreach($_POST['locstage'] AS $valeur3)
{
if(ISSET($_POST['locstage'])&&$_POST['locstage']!='')
{
if($exp) $exp .= ' OR ';
$exp .= ' pl.LocStage="'.$valeur3.'"';
}
}
$where = $exp . ') ';
}
if($exp){$exp='');
if( !$exp ) $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";
/*
Je ne sais pas si ça va marcher mais bon essaye quad même ...
*/
?>
<?php
/*
Pour ma part j'utiliserais les fonctions currnet, key et next pour naviguer dans les tableaux
*/
do{
$val = current($_POST['tostageto']); // on recupère la valeur de la case du tableau
$key = key($_POST['stage']); // on résupère la clé
if($exp) $exp .= ' OR ';
$exp .= ' pl.LocStage="'.$val.'"';
}while(!next($_POST['stage']));
$where .= $exp.') ';
?>
Essaye cela, je ne sais pas si ça va marcher, je n'ai pas modifier grand chose...
<?php
array('Performer', 'Panel','Workshop');
array('5/26/2006','5/27/2006','5/28/2006','5/29/2006');
array('Indoor', 'Outdoor');
$where = 'WHERE (';
unset($exp); // on libère la variable au cas où elle existe et possède une valeur
if( ISSET($_POST['perfname']) && $_POST['perfname'] != '' )
{
$exp = ' (pr.PerfName="'.$_POST['perfname'].'"';
}
$where .= $exp;
if($exp){$exp = '';}
if( isset($_POST['typeperf']) AND is_array($_POST['typeperf']) )
{
foreach($_POST['typeperf'] AS $valeur)
{
if( ISSET($_POST['typeperf']) && $_POST['typeperf'] != '' )
{
if($exp) $exp .= ' OR ';
$exp .= ' pr.TypePerf="'.$valeur.'"';
}
}
$where .= $exp . ') ';
}
if($exp){$exp = '';}
if( ISSET($_POST['perfcodename']) && $_POST['perfcodename'] != '' )
{
if($exp) $exp .= ' AND ';
$exp .= ' pr.PerfCodeName="'.$_POST['perfcodename'].'"';
}
$where .= $exp;
if($exp){$exp='');
if( isset($_POST['date']) AND is_array($_POST['date']) )
{
foreach($_POST['date'] AS $valeur2)
{
if(ISSET($_POST['date']) && $_POST['date'] != '' )
{
if($exp) $exp .= ' OR ';
$exp .=' pf.Date="'.$valeur2.'"';
}
}
$where .= $exp . ') ';
}
if($exp){$exp='');
if(ISSET($_POST['start']) && $_POST['start'] != '' )
{
if($exp) $exp .= ' AND ';
$exp .= ' pf.Start="'.$_POST['start'].'"';
}
$where .= $exp;
if($exp){$exp='');
if( ISSET($_POST['end']) && $_POST['end'] != '' )
{
if($exp) $exp .= ' AND ';
$exp = ' pf.End="'.$_POST['end'].'"';
}
$where .= $exp;
if($exp){$exp='');
if( ISSET($_POST['stage']) && $_POST['stage'] != '' )
{
if($exp) $exp .= ' AND ';
$exp .= ' pl.Stage="'.$_POST['stage'].'"';
}
$where .= $exp;
if($exp){$exp='');
if(isset($_POST['locstage']) AND is_array($_POST['locstage']))
{
foreach($_POST['locstage'] AS $valeur3)
{
if(ISSET($_POST['locstage'])&&$_POST['locstage']!='')
{
if($exp) $exp .= ' OR ';
$exp .= ' pl.LocStage="'.$valeur3.'"';
}
}
$where = $exp . ') ';
}
if($exp){$exp='');
if( !$exp ) $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";
/*
Je ne sais pas si ça va marcher mais bon essaye quad même ...
*/
?>
<?php
/*
Pour ma part j'utiliserais les fonctions currnet, key et next pour naviguer dans les tableaux
*/
do{
$val = current($_POST['tostageto']); // on recupère la valeur de la case du tableau
$key = key($_POST['stage']); // on résupère la clé
if($exp) $exp .= ' OR ';
$exp .= ' pl.LocStage="'.$val.'"';
}while(!next($_POST['stage']));
$where .= $exp.') ';
?>
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";