requête découpé en plusieurs bouts
Posté : 03 déc. 2007, 14:09
Hello tout le monde en ce lundi,
Me revoici avec un petit soucis.
Voici avant tout mon code :
Merci d'avance 
ps : je n'étais aps sur de devoir mettre le sujet ici ou dans php
Me revoici avec un petit soucis.
Voici avant tout mon code :
if($_POST['rechercher'])
{
$sql = 'SELECT DISTINCT id, nom, prenom, age, taille, salaire, tir, 3points, dribble, passe, rebond, contre, interception
FROM joueurs INNER JOIN transferts ON joueurs.id = transferts.id_joueur
WHERE date_fin >='.time().'';
if($_POST['age_mini'] && is_numeric($_POST['age_mini']))
{
$sql.= 'AND age >='.$_POST['age_mini'].'';
}
if($_POST['age_max'] && is_numeric($_POST['age_mini']))
{
$sql.= ' AND age <='.$_POST['age_max'].'';
}
if($_POST['skill_mini'] && is_numeric($_POST['skill_mini']))
{
$sql.= ' AND age >='.$_POST['skill_mini'].'';
}
if($_POST['skill_max'] && is_numeric($_POST['age_max']))
{
$sql.= ' AND age <='.$_POST['skill_max'].'';
}
if($_POST['prix_mini'] && is_numeric($_POST['prix_mini']))
{
$sql.= ' AND prix >='.$_POST['prix_mini'].'';
}
if($_POST['prix_max'] && is_numeric($_POST['prix_max']))
{
$sql.= ' AND prix <='.$_POST['prix_max'].'';
}
if($_POST['taille_mini'] && is_numeric($_POST['taille_mini']))
{
$sql.= ' AND taille >='.$_POST['taille_mini'].'';
}
if($_POST['taille_max'] && is_numeric($_POST['taille_max']))
{
$sql.= ' AND taille <='.$_POST['taille_max'].'';
}
echo $sql.'<br />';
$requete = mysql_query($sql) or die (mysql_error()) ;
}
echo $sql.'<br />';
$requete = mysql_query($sql) or die (mysql_error()) ;
Voici ma requete affichée ainsi que l'erreur.: A mon avis je place mal mes apostrophes mais après plusieurs tentatives je n'arrive pas à résoudre le problème...SELECT DISTINCT id, nom, prenom, age, taille, salaire, tir, 3points, dribble, passe, rebond, contre, interception FROM joueurs INNER JOIN transferts ON joueurs.id = transferts.id_joueur WHERE date_fin >=1196683243AND age >=17 AND age <=39 AND taille >=150 AND taille <=240
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'age >=17 AND age <=39 AND taille >=150 AND taille <=240' at line
Code : Tout sélectionner
--
-- Structure de la table `transferts`
--
CREATE TABLE `transferts` (
`id` int(11) NOT NULL auto_increment,
`id_joueur` int(11) NOT NULL,
`id_equipe_v` int(11) NOT NULL,
`id_equipe_a` int(11) NOT NULL,
`date_debut` int(11) NOT NULL,
`date_fin` int(11) NOT NULL,
`prix` int(11) NOT NULL,
UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci AUTO_INCREMENT=3 ;
--
-- Structure de la table `joueurs`
--
CREATE TABLE `joueurs` (
`id` int(11) NOT NULL auto_increment,
`id_equipe` int(11) NOT NULL,
`nom` varchar(255) collate latin1_german2_ci NOT NULL,
`prenom` varchar(255) collate latin1_german2_ci NOT NULL,
`nationalite` varchar(255) collate latin1_german2_ci NOT NULL,
`age` tinyint(4) NOT NULL,
`taille` smallint(6) NOT NULL,
`salaire` int(11) NOT NULL,
`specialite` varchar(255) collate latin1_german2_ci NOT NULL,
`temperament` varchar(255) collate latin1_german2_ci NOT NULL,
`agressivite` varchar(255) collate latin1_german2_ci NOT NULL,
`tir` smallint(6) NOT NULL,
`3points` smallint(11) NOT NULL,
`dribble` smallint(6) NOT NULL,
`passe` smallint(6) NOT NULL,
`rebond` smallint(6) NOT NULL,
`contre` smallint(6) NOT NULL,
`interception` smallint(6) NOT NULL,
`fatigue` smallint(11) NOT NULL default '0',
UNIQUE KEY `id_2` (`id`),
UNIQUE KEY `id_3` (`id`),
KEY `id` (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=351 DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci AUTO_INCREMENT=351 ;
ps : je n'étais aps sur de devoir mettre le sujet ici ou dans php