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 :

Vérifier un code postal


Sujet :

Langage PHP

  1. #1
    Nouveau membre du Club
    Inscrit en
    Février 2004
    Messages
    55
    Détails du profil
    Informations forums :
    Inscription : Février 2004
    Messages : 55
    Points : 31
    Points
    31
    Par défaut Vérifier un code postal
    bonjour a tous...
    voila, donc je cherche a faire fusionner 2 codes que j'ai fait mais
    je voi pas pour le moment la solution... je pense que c'est simple
    mais je bloque


    pour expliquer :
    les codes sont pour réaliser un moteur de recherche interne de petite
    annonces.
    - Le 1 code est pour la receheche de "ville,CP,Département".
    - Le 2 code pour faire une recherche de CP, exemple on tape
    32200 et sa va cherche entre 100ou ou autre de plus ou moin.
    (de 32100 à 32300).

    Le bute :
    le bute de la fusion est de pouvoir détecter les CP du 1 code
    pour leur apliquer la recherche du 2 code. puis faire la recherche..

    1 code :
    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
     
    $informations = strtolower(@$_GET['informations']);
    $informations = str_replace(", ", " ", trim($informations)); 
    $informations = str_replace(",", " ", $informations); 
    $informations = str_replace("; ", " ", $informations);
    $informations = str_replace(";", " ", $informations);
    $informations = str_replace("+", " ", $informations); 
    $informations = str_replace("\"", " ", $informations);
    $informations = str_replace(":", " ", $informations);
    $tab=explode(" " , $informations);
     
     if ($tab[0] != '' || $tab[1] != '' || $tab[2] != '' || $tab[3] != '' || $tab[4] != '')
    { 
     $query_search .= "
    AND ((products.departement = '$tab[0]') OR (products.ville = '$tab[0]') OR (products.codepostal = '$tab[0]')
    OR (products.departement = '$tab[1]') OR (products.ville = '$tab[1]') OR (products.codepostal = '$tab[1]')
    OR (products.departement = '$tab[2]') OR (products.ville = '$tab[2]') OR (products.codepostal = '$tab[2]')
    OR (products.departement = '$tab[3]') OR (products.ville = '$tab[3]') OR (products.codepostal = '$tab[3]')
    OR (products.departement = '$tab[4]') OR (products.ville = '$tab[4]') OR (products.codepostal = '$tab[4]'))";
    }
    2 code :
    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
     
    $val =trim(@$_GET['codepostal']); 
    $fourchette =trim(@$_GET['distance']); 
    if($val == '') { 
       $val_mini = "00000"; 
       $val_maxi = "99999"; 
       $query_search .= " AND products.codepostal BETWEEN ". $val_mini ." AND ". $val_maxi; 
    }elseif($fourchette == '') { 
       $val = intval($val); 
       if ($val < 0) $val = -$val; 
       $query_search .= " AND products.codepostal = ".$val;
    }else { 
       $fourchette = intval(substr($fourchette,0,3)); 
       $val = intval($val); 
       if ($val < 0) $val = -$val; 
       $departm = intval($val/1000); 
       $departm_mini = 1000*$departm; 
       $departm_maxi = $departm_mini + 999; 
       $val_mini = $val-$fourchette; 
       $val_maxi = $val+$fourchette; 
       if ($val_mini < $departm_mini) $val_mini = $departm_mini; 
       if ($val_maxi > $departm_maxi) $val_maxi = $departm_maxi; 
       $query_search .= " AND products.codepostal BETWEEN ". $val_mini ." AND ". $val_maxi; 
    }

    en faite je c'est pas comment faire pour trouver les codes a 5 chiffres pour les tréter...
    Je reste ouvert a toutes remarques ou indices

    je pense a un truc...

    en faite il me faut juste savoir ci ($tab[0] ou $tab[1]...) son bien
    des chiffres a 5 chiffres puis je les donnes au 2 code.


    du style :

    If ($tab[0] != ???) {
    2 code }

    If ($tab[1] != ???) {
    2 code }

    Ma question est :
    comment faire cette vérification ???

    j'ai testé avec :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    if( ! preg_match( '/[0-9]{5}$/', $tab[0] ) ){	
     
    2 code
     
    }
    Mais sa ne marche pas

  2. #2
    Nouveau membre du Club
    Inscrit en
    Février 2004
    Messages
    55
    Détails du profil
    Informations forums :
    Inscription : Février 2004
    Messages : 55
    Points : 31
    Points
    31
    Par défaut ok
    bonjour a tous, voila donc j'ai trouvé la réponse a mon probleme
    je laisse la réponse plus bas car peut etre pour des personnes qui cherche
    a faire la meme chose auront la solution a porté de main

    la seul chose renseigner pour que sa marche nikel est :
    @$_GET['informations']
    @$_GET['fourchette']

    ci on fait une recherche du style :
    INPUT = '07200,55400,94200'
    La fourchette s'apppplique a tous est va chercher dans la base
    les résultat a affficher...

    je pense que l'on peu faire mieu mais je suis pas vraiment en Pro LoL
    mais sa marche nikel sans erreur :-)

    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
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
     
    $informations = strtolower(@$_GET['informations']);
    $informations = str_replace(", ", " ", trim($informations)); 
    $informations = str_replace(",", " ", $informations); 
    $informations = str_replace("; ", " ", $informations);
    $informations = str_replace(";", " ", $informations);
    $informations = str_replace("+", " ", $informations); 
    $informations = str_replace("\"", " ", $informations);
    $informations = str_replace(":", " ", $informations);
    $tab=explode(" " , $informations);
     
     
    if ($tab[0] != '' || $tab[1] != '' || $tab[2] != '') {
    if (ereg ("([0-9]{5})", $tab[0])) {
    $val1 = $tab[0];
    } else {
    $val_mini1 = "00000"; 
    $val_maxi1 = "99999"; 
    }
    if (ereg ("([0-9]{5})", $tab[1])) {
    $val2 = $tab[1];
    } else {
    $val_mini2 = "00000"; 
    $val_maxi2 = "99999"; 
    }
    if (ereg ("([0-9]{5})", $tab[2])) {
    $val3 = $tab[2];
    } else {
    $val_mini3 = "00000"; 
    $val_maxi3 = "99999"; 
    }
     
       $fourchette = '100';
     
       $fourchette = intval(substr($fourchette,0,3)); 
     
       $val1 = intval($val1);
       $val2 = intval($val2);
       $val3 = intval($val3);
     
       if ($val1 < 0) $val1 = -$val1; 
       if ($val2 < 0) $val2 = -$val2;
       if ($val3 < 0) $val3 = -$val3;
     
       $departm1 = intval($val1/1000);
       $departm2 = intval($val2/1000);
       $departm3 = intval($val3/1000);
     
       $departm_mini1 = 1000*$departm1; 
       $departm_mini2 = 1000*$departm2;
       $departm_mini3 = 1000*$departm3;
     
       $departm_maxi1 = $departm_mini1 + 999; 
       $departm_maxi2 = $departm_mini2 + 999;
       $departm_maxi3 = $departm_mini3 + 999;
     
       $val_mini1 = $val1-$fourchette; 
       $val_mini2 = $val2-$fourchette;
       $val_mini3 = $val3-$fourchette;
     
       $val_maxi1 = $val1+$fourchette; 
       $val_maxi2 = $val2+$fourchette;
       $val_maxi3 = $val3+$fourchette;
     
       if ($val_mini1 < $departm_mini1) $val_mini1 = $departm_mini1; 
       if ($val_mini2 < $departm_mini2) $val_mini2 = $departm_mini2;
       if ($val_mini3 < $departm_mini3) $val_mini3 = $departm_mini3;
     
       if ($val_maxi1 > $departm_maxi1) $val_maxi1 = $departm_maxi1; 
       if ($val_maxi2 > $departm_maxi2) $val_maxi2 = $departm_maxi2;
       if ($val_maxi3 > $departm_maxi3) $val_maxi3 = $departm_maxi3;
     
       $query_search .= "
    AND ((products.codepostal BETWEEN  '$val_mini1' AND  '$val_maxi1')
    OR (products.codepostal BETWEEN  '$val_mini2' AND  '$val_maxi2')
    OR (products.codepostal BETWEEN  '$val_mini3' AND  '$val_maxi3') 
    OR (products.departement = '$tab[0]') OR (products.ville = '$tab[0]') OR (products.codepostal = '$tab[0]')
    OR (products.departement = '$tab[1]') OR (products.ville = '$tab[1]') OR (products.codepostal = '$tab[1]')
    OR (products.departement = '$tab[2]') OR (products.ville = '$tab[2]') OR (products.codepostal = '$tab[2]'))"; 
     }

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

Discussions similaires

  1. Vérifier le mappage Ville / Code postal
    Par boubil dans le forum Requêtes
    Réponses: 6
    Dernier message: 12/10/2012, 23h00
  2. Réponses: 5
    Dernier message: 24/01/2006, 14h25
  3. type de colonne pour numéro de tél et code postal
    Par molesqualeux dans le forum Requêtes
    Réponses: 2
    Dernier message: 19/01/2006, 14h19
  4. pb pour la validité d'un code postal
    Par hoaxpunk dans le forum Général JavaScript
    Réponses: 7
    Dernier message: 14/12/2005, 11h35
  5. novice: code postale et ville
    Par Chico_Latino dans le forum Access
    Réponses: 5
    Dernier message: 15/11/2005, 20h03

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