Précédent   Forum des professionnels en informatique > PHP > Langage > Syntaxe
Syntaxe Forum d'entraide sur la syntaxe de PHP et la POO. Avant de poster -> FAQ syntaxe, Cours d'initiation et cours de POO
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 01/11/2007, 21h23   #1
Futur Membre du Club
 
Inscription : février 2004
Messages : 55
Détails du profil
Informations forums :
Inscription : février 2004
Messages : 55
Points : 19
Points : 19
Envoyer un message via AIM à weldoo
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 :
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 :
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 :
1
2
3
4
5
6
 
if( ! preg_match( '/[0-9]{5}$/', $tab[0] ) ){	
 
2 code
 
}
Mais sa ne marche pas
weldoo est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/11/2007, 16h40   #2
Futur Membre du Club
 
Inscription : février 2004
Messages : 55
Détails du profil
Informations forums :
Inscription : février 2004
Messages : 55
Points : 19
Points : 19
Envoyer un message via AIM à weldoo
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 :
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]'))"; 
 }
weldoo est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 04h33.


 
 
 
 
Partenaires

Hébergement Web