Bonjour,
J'ai un souci pour faire une modif en php, j'aimerais votre aident svp.
Je vais essayer d'être la plus claire possible.
Sur mon site j'ai une liste des dernières annonces classer selon une région, à la première visite de l'internaute si aucune région n'a était choisie alors est afficher une région par défaut avec cette variable:
Id -14 correspond à la région iles de france pour mieux comprendre voici l'architecture de ma table :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 // the first city in the database will be taken as the default. $default_city = -14;
table countries
la fonction variable qui permet de choisir un id region est ici :
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 -- -- Structure de la table `countries` -- CREATE TABLE IF NOT EXISTS `countries` ( `countryid` smallint(5) unsigned NOT NULL auto_increment, `countryname` varchar(50) NOT NULL default '', `pos` smallint(5) unsigned NOT NULL default '0', `enabled` enum('0','1') NOT NULL default '0', `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, PRIMARY KEY (`countryid`), KEY `pos` (`pos`), KEY `enabled` (`enabled`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=25 ; -- -- Contenu de la table `countries` -- INSERT INTO `countries` (`countryid`, `countryname`, `pos`, `enabled`, `timestamp`) VALUES (2, 'Alsace', 1, '1', '2008-12-03 00:28:35'), (3, 'Aquitaine', 2, '1', '2008-12-03 00:28:35'), (4, 'Auvergne', 3, '1', '2008-12-03 00:28:35'), (5, 'Basse Normandie', 4, '1', '2008-12-03 00:28:35'), (6, 'Bourgogne', 5, '1', '2008-12-03 00:28:35'), (7, 'Bretagne', 6, '1', '2008-12-03 00:28:35'), (8, 'Centre Val de Loire', 7, '1', '2008-12-03 00:28:35'), (9, 'Champagne-Ardenne', 8, '1', '2008-12-03 00:28:35'), (10, 'Corse', 9, '1', '2008-12-03 00:28:35'), (11, 'Dom-Tom', 10, '1', '2008-12-03 00:28:35'), (12, 'Franche-Comté', 11, '1', '2008-12-03 00:28:35'), (13, 'Haute Normandie', 12, '1', '2008-12-03 00:28:35'), (14, 'Ile de France', 13, '1', '2008-12-03 00:28:35'), (15, 'Languedoc-Roussillon', 14, '1', '2008-12-03 00:28:35'), (16, 'Limousin', 15, '1', '2008-12-03 00:28:35'), (17, 'Lorraine', 16, '1', '2008-12-03 00:28:35'), (18, 'Midi-Pyrénées', 17, '1', '2008-12-03 00:28:35'), (19, 'Nord-Pas-de-Calais', 18, '1', '2008-12-03 00:28:35'), (20, 'PACA', 19, '1', '2008-12-03 00:28:35'), (21, 'Pays de la Loire', 20, '1', '2008-12-03 00:28:35'), (22, 'Picardie', 21, '1', '2008-12-03 00:28:35'), (23, 'Poitou-Charentes', 22, '1', '2008-12-03 00:28:35'), (24, 'Rhône-Alpes', 23, '1', '2008-12-03 00:28:35');
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 // Get current city if ($_GET['cityid'] > 0) { $xcityid = $_GET['cityid']; } elseif ($_GET['cityid'] < 0) { $xcountryid = abs($_GET['cityid']); $xcityid = $_GET['cityid']; } elseif ($_COOKIE[$ck_cityid] > 0) { $xcityid = $_COOKIE[$ck_cityid]; } elseif ($_COOKIE[$ck_cityid] < 0) { $xcountryid = abs($_COOKIE[$ck_cityid]); $xcityid = $_COOKIE[$ck_cityid]; } elseif ($default_city) { $xcityid = $default_city; if($xcityid < 0) $xcountryid = -($xcityid); } if ($xcityid) { if ($xcityid > 0) $sql = "SELECT COUNT(*) FROM $t_cities WHERE cityid = '$xcityid'"; else $sql = "SELECT COUNT(*) FROM $t_countries WHERE countryid = '$xcountryid'"; list($city_exists) = @mysql_fetch_array(mysql_query($sql)); if(!$city_exists) $xcityid = 0; } /*if(!$xcityid) { $sql = "SELECT countryid FROM $t_countries WHERE enabled = '1' LIMIT 1"; list($xcountryid) = mysql_fetch_array(mysql_query($sql)); $xcityid = 0-$xcountryid; }*/ if(!$xcityid) { $sql = "SELECT cityid FROM $t_cities WHERE enabled = '1' LIMIT 1"; list($xcityid) = @mysql_fetch_array(mysql_query($sql)); } if (!$xcityid && !$in_admin) { die("No locations defined!"); } setcookie($ck_cityid, $xcityid, time()+(60*24*60*60), "/"); // Get city name if ($xcityid > 0) { $sql = "SELECT c.countryname, c.countryid, ct.cityname FROM $t_cities ct INNER JOIN $t_countries c ON c.countryid = ct.countryid WHERE cityid = '$xcityid'"; list($xcountryname, $xcountryid, $xcityname)= @mysql_fetch_array(mysql_query($sql)); } elseif ($xcountryid) { $sql = "SELECT c.countryname FROM $t_countries c WHERE countryid = '$xcountryid'"; list($xcountryname)= @mysql_fetch_array(mysql_query($sql)); $xcityname = $xcountryname; }
Vous allez me dire et ou est le problème !
Et bien en faite j'essaie depuis hier de faire un select sur toutes les id régions en même temps au lieu d'être limiter à faire un choix sur un id région.
En gros si c'est la première visite de l'internaute alors lui afficher les dernières annonces de toutes les région et pas uniquement la région -14 (ile de france).
Quelqu'un pourrais m'aider, merci d'avance.
Partager