Oui je comprends il faut dire que le code n'est pas très lisible sur le poste et j'ai pris une mauvaise manie de pas commenter mon code.
Bon je vais reprendre au début car je tes pas tout donner les infos pour que tu puisse m'aider.
Voici la structure des 3 tables en question :--
-- 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');
-- --------------------------------------------------------
--
-- Structure de la table `cities`
--
CREATE TABLE IF NOT EXISTS `cities` (
`cityid` smallint(5) unsigned NOT NULL auto_increment,
`cityname` varchar(50) NOT NULL default '',
`countryid` smallint(5) unsigned NOT NULL default '0',
`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 (`cityid`),
KEY `countryid` (`countryid`),
KEY `pos` (`pos`),
KEY `enabled` (`enabled`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=103 ;
--
-- Contenu de la table `cities`
--
INSERT INTO `cities` (`cityid`, `cityname`, `countryid`, `pos`, `enabled`, `timestamp`) VALUES
(2, '67 - Bas-Rhin', 2, 1, '1', '2008-12-03 00:28:35'),
(3, '68 - Haut-Rhin', 2, 2, '1', '2008-12-03 00:28:35'),
(4, '24 - Dordogne', 3, 3, '1', '2008-12-03 00:28:35'),
(5, '33 - Gironde', 3, 4, '1', '2008-12-03 00:28:35'),
(6, '40 - Landes', 3, 5, '1', '2008-12-03 00:28:35'),
(7, '47 - Lot-et-Garonne', 3, 6, '1', '2008-12-03 00:28:35'),
(8, '64 - Pyrénées-Atlantiques', 3, 7, '1', '2008-12-03 00:28:35'),
(9, '03 - Allier', 4, 8, '1', '2008-12-03 00:28:35'),
(10, '15 - Cantal', 4, 9, '1', '2008-12-03 00:28:35'),
(11, '43 - Haute-Loire', 4, 10, '1', '2008-12-03 00:28:35'),
(12, '63 - Puy-de-Dôme', 4, 11, '1', '2008-12-03 00:28:35'),
(13, '14 - Calvados', 5, 12, '1', '2008-12-03 00:28:35'),
(14, '50 - Manche', 5, 13, '1', '2008-12-03 00:28:35'),
(15, '61 - Orne', 5, 14, '1', '2008-12-03 00:28:35'),
(16, '21 - Côte-d''Or', 6, 15, '1', '2008-12-03 00:28:35'),
(17, '58 - Nièvre', 6, 16, '1', '2008-12-03 00:28:35'),
blablabla ....
-- --------------------------------------------------------
--
-- Structure de la table `areas`
--
CREATE TABLE IF NOT EXISTS `areas` (
`areaid` smallint(5) unsigned NOT NULL auto_increment,
`areaname` varchar(50) NOT NULL default '',
`cityid` smallint(5) unsigned NOT NULL default '0',
`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 (`areaid`),
KEY `pos` (`pos`),
KEY `cityid` (`cityid`),
KEY `enabled` (`enabled`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
--
-- Contenu de la table `areas`
--
Que j'utilise pas encore
Maintenant la fonction variable que je me sert pour définir un id région (une région à afficher par défaut) si aucune région n'a été encore choisie.// ID of the default city. If u want to use a region as default,
// enter the region id preceeded with a '-'. Set this to 0 and
// the first city in the database will be taken as the default. ( Soit -14 = id de la région ile de france )
$default_city = -14;Les variables en question :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 cityid
FROM $t_cities
WHERE enabled = '1'
LIMIT 1";
list($xcityid) = @mysql_fetch_array(mysql_query($sql));
}
ps: Se que tu me propose ne conviens pas