IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Parse error T_IF


Sujet :

Langage PHP

  1. #1
    En attente de confirmation mail
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    49
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 49
    Points : 41
    Points
    41
    Par défaut Parse error T_IF
    Bonjour,

    Je suis en train d'essayer de rajouter un if dans la requête ci-dessous qui fonctionne bien :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    	$updates_raw = 	"select * from " 
    			. TABLE_PRODUCTS_DESCRIPTION . " pd, " 
    			. TABLE_PRODUCTS 
    			. " p LEFT JOIN " 
    			. TABLE_MANUFACTURERS . " m "
    			. "ON "
    			. "( p.manufacturers_id = m.manufacturers_id ) "
    			. " LEFT JOIN "
    			. TABLE_PRODUCTS_TO_CATEGORIES . " ptc "
    			. " ON "
    			. "( p.products_id 	= ptc.products_id ) "
    			. " LEFT JOIN "
    			. TABLE_CATEGORIES_DESCRIPTION . " cd "
    			. " ON "
    			. "( ptc.categories_id 	= cd.categories_id ) "
    			. "where "
    			. "p.products_id = pd.products_id "
    			. "and "
    			. "pd.language_id = $languages_id "
    			. "and "
    			. "cd.language_id = $languages_id "
    			. "and "
    			. "( pd.products_name like '%" . $keywords . "%' "
    			. "or "
    			. "p.products_model like '%" . $keywords . "%' "
    			. "or "
    			. "cd.categories_name like '%" . $keywords . "%' "
    			. "or "
    			. "m.manufacturers_name like '%" . $keywords . "%' ) "
    			. "and "
    			. " cd.categories_id = " . $categories
    			. " order by "
    			. "$order "
     
    	; // END updates_raw

    Voila requête lorsque j'ai rajouté mon if (en bas de la requete)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    	$updates_raw = 	"select * from " 
    			. TABLE_PRODUCTS_DESCRIPTION . " pd, " 
    			. TABLE_PRODUCTS 
    			. " p LEFT JOIN " 
    			. TABLE_MANUFACTURERS . " m "
    			. "ON "
    			. "( p.manufacturers_id = m.manufacturers_id ) "
     
    			//Fab
    			. " LEFT JOIN "
    			. TABLE_PRODUCTS_TO_CATEGORIES . " ptc "
    			. " ON "
    			. "( p.products_id 	= ptc.products_id ) "
    			. " LEFT JOIN "
    			. TABLE_CATEGORIES_DESCRIPTION . " cd "
    			. " ON "
    			. "( ptc.categories_id 	= cd.categories_id ) "
    			. "where "
    			. "p.products_id = pd.products_id "
    			. "and "
    			. "pd.language_id = $languages_id "
    			. "and "
    			. "cd.language_id = $languages_id "
    			. "and "
    			. "( pd.products_name like '%" . $keywords . "%' "
    			. "or "
    			. "p.products_model like '%" . $keywords . "%' "
    			. "or "
    			. "cd.categories_name like '%" . $keywords . "%' "
    			. "or "
    			. "m.manufacturers_name like '%" . $keywords . "%' ) "
    			. if ($categories == 0) {
    			. "and "
    			. " cd.categories_id = " . $categories
    			}
    			. " order by "
    			. "$order "
     
    	; // END updates_raw

    Qu'est ce qui ne vas pas dans la syntax suivante? :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    			. if ($categories == 0) {
    			. "and "
    			. " cd.categories_id = " . $categories
    			}
    Voici l'erreur :

    arse error: syntax error, unexpected T_IF in



    Merci de votre aide à tous.

  2. #2
    Membre actif Avatar de Alshten
    Homme Profil pro
    Développeur Web
    Inscrit en
    Novembre 2005
    Messages
    157
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Novembre 2005
    Messages : 157
    Points : 233
    Points
    233
    Par défaut
    Tu peux pas ajouter un IF en plein milieu d'une concaténation comme ça.

    Si tu veux faire comme ça, utilise plutôt les opérateurs comme ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    .($categorie == 0 ? "and cd.categories_id = " . $categories : "").

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    625
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 625
    Points : 822
    Points
    822
    Par défaut
    Tu n'as tout simplement pas le droit de rajouter une structure de controle dans une concaténation.

    Il faudrait que tu passes par quelque chose comme ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
     
    $updates_raw = 	"select * from " 
    			. TABLE_PRODUCTS_DESCRIPTION . " pd, " 
    			. TABLE_PRODUCTS 
    			. " p LEFT JOIN " 
    			. TABLE_MANUFACTURERS . " m "
    			. "ON "
    			. "( p.manufacturers_id = m.manufacturers_id ) "
     
    			//Fab
    			. " LEFT JOIN "
    			. TABLE_PRODUCTS_TO_CATEGORIES . " ptc "
    			. " ON "
    			. "( p.products_id 	= ptc.products_id ) "
    			. " LEFT JOIN "
    			. TABLE_CATEGORIES_DESCRIPTION . " cd "
    			. " ON "
    			. "( ptc.categories_id 	= cd.categories_id ) "
    			. "where "
    			. "p.products_id = pd.products_id "
    			. "and "
    			. "pd.language_id = $languages_id "
    			. "and "
    			. "cd.language_id = $languages_id "
    			. "and "
    			. "( pd.products_name like '%" . $keywords . "%' "
    			. "or "
    			. "p.products_model like '%" . $keywords . "%' "
    			. "or "
    			. "cd.categories_name like '%" . $keywords . "%' "
    			. "or "
    			. "m.manufacturers_name like '%" . $keywords . "%' ) ";
    if ($categories == 0) {
    		$updates_raw .= "and "
    			. " cd.categories_id = " . $categories;
    }
    		$updates_raw .= " order by "
    			. "$order "
     
    	; // END updates_raw
    Tu arrêtes ta concaténation pour la reprendre.

    Sinon tu peux t'appuyer sur une condition ternaire (condition ? true : false ) pour te simplifier la vie :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $updates_raw = "blablabla .... " . ($categories == 0 ? "and blablablah " : "" ) . " blablablah ";

  4. #4
    En attente de confirmation mail
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    49
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 49
    Points : 41
    Points
    41
    Par défaut
    Merci à tous

    Excellent le coup du

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    			. "m.manufacturers_name like '%" . $keywords . "%' ) ";
    if ($categories == 0) {
    		$updates_raw .= "and "
    			. " cd.categories_id = " . $categories;
    }
    		$updates_raw .= " order by "
    			. "$order "
    Merci et bonne journée à tous

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 4
    Dernier message: 01/02/2011, 17h32
  2. parse error
    Par Romain93 dans le forum C
    Réponses: 6
    Dernier message: 28/09/2005, 21h03
  3. je ne comprend pas un parse error
    Par bibi_64 dans le forum C
    Réponses: 3
    Dernier message: 21/09/2005, 14h00
  4. XML Parsing Error: not well-formed
    Par localhost dans le forum Valider
    Réponses: 5
    Dernier message: 16/06/2005, 14h20
  5. Parse error
    Par Sylvain James dans le forum XMLRAD
    Réponses: 2
    Dernier message: 02/02/2005, 10h55

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo