We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36970
    • 23 Posts
    I did it but it is showing me all districts for any of the region and same for towns (all towns for any district). In tsTown is it supposed to be town as idfield or id ?
      • 4172
      • 5,888 Posts
      can you show your sql-dumps of your three table-contents?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 36970
        • 23 Posts
        --
        -- Table structure for table `modx_ts_districts`
        --

        CREATE TABLE IF NOT EXISTS `modx_ts_districts` (
        `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `district` varchar(255) NOT NULL DEFAULT '',
        `region_id` int(11) NOT NULL DEFAULT '0',
        PRIMARY KEY (`id`)
        ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=25 ;

        --
        -- Dumping data for table `modx_ts_districts`
        --

        INSERT INTO `modx_ts_districts` (`id`, `district`, `region_id`) VALUES
        (1, 'Bratislava I', 1),
        (2, 'Bratislava II', 1),
        (3, 'Bratislava III', 1),
        (4, 'Bratislava IV', 1),
        (5, 'Bratislava V', 1),
        (6, 'Malacky', 1),
        (7, 'Pezinok', 1),
        (8, 'Senec', 1),
        (9, 'Dunajská Streda', 2),
        (10, 'Galanta', 2),
        (11, 'Hlohovec', 2),
        (12, 'Piešťany', 2),
        (13, 'Senica', 2),
        (14, 'Skalica', 2),
        (15, 'Trnava', 2),
        (16, 'Bánovce nad Bebravou', 3),
        (17, 'Ilava', 3),
        (18, 'Myjava', 3),
        (19, 'Nové Mesto nad Váhom', 3),
        (20, 'Partizánske', 3),
        (21, 'Považská Bystrica', 3),
        (22, 'Prievidza', 3),
        (23, 'Púchov', 3),
        (24, 'Trenčín', 3);

        -- --------------------------------------------------------

        --
        -- Table structure for table `modx_ts_regions`
        --

        CREATE TABLE IF NOT EXISTS `modx_ts_regions` (
        `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `region` varchar(255) NOT NULL DEFAULT '',
        PRIMARY KEY (`id`)
        ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=9 ;

        --
        -- Dumping data for table `modx_ts_regions`
        --

        INSERT INTO `modx_ts_regions` (`id`, `region`) VALUES
        (1, 'Bratislavský Kraj'),
        (2, 'Trnavský Kraj'),
        (3, 'Trenčiansky Kraj'),
        (4, 'Nitriansky Kraj'),
        (5, 'Žilinský Kraj'),
        (6, 'Banskobystrický Kraj'),
        (7, 'Prešovský Kraj'),
        (8, 'Košický Kraj');

        -- --------------------------------------------------------

        --
        -- Table structure for table `modx_ts_towns`
        --

        CREATE TABLE IF NOT EXISTS `modx_ts_towns` (
        `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `town` varchar(255) NOT NULL DEFAULT '',
        `district_id` int(11) NOT NULL DEFAULT '0',
        PRIMARY KEY (`id`)
        ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=35 ;

        --
        -- Dumping data for table `modx_ts_towns`
        --

        INSERT INTO `modx_ts_towns` (`id`, `town`, `district_id`) VALUES
        (1, 'Beckov', 19),
        (2, 'Bošáca', 19),
        (3, 'Brunovce', 19),
        (4, 'Bzince pod Javorinou', 19),
        (5, 'Čachtice', 19),
        (6, 'Častkovce', 19),
        (7, 'Dolné Srnie', 19),
        (8, 'Haluzice', 19),
        (9, 'Horná Streda', 19),
        (10, 'Hôrka nad Váhom', 19),
        (11, 'Hrádok', 19),
        (12, 'Hrachovište', 19),
        (13, 'Kálnica', 19),
        (14, 'Kočovce', 19),
        (15, 'Lubina', 19),
        (16, 'Lúka', 19),
        (17, 'Modrová', 19),
        (18, 'Modrovka', 19),
        (19, 'Moravské Lieskové', 19),
        (20, 'Nová Bošáca', 19),
        (21, 'Nová Lehota', 19),
        (22, 'Nová Ves nad Váhom', 19),
        (23, 'Očkov', 19),
        (24, 'Pobedim', 19),
        (25, 'Podolie', 19),
        (26, 'Potvorice', 19),
        (27, 'Považany', 19),
        (28, 'Stará Lehota', 19),
        (29, 'Trenčianske Bohuslavice', 19),
        (30, 'Vaďovce', 19),
        (31, 'Višňové', 19),
        (32, 'Zemianske Podhradie', 19),
        (33, 'Nové Mesto nad Váhom', 19),
        (34, ' Stará Turá', 19);
          • 4172
          • 5,888 Posts
          sorry, had forgotten to add the where - values:

          name: tsRegion
          input type: dynamic_dropdown
          dddx Group: townsselector
          first row text: -- choose Region --
          packagename: townsselector
          classname: tsRegion
          idfield: id
          namefield: region

          name: tsDistrict
          input type: dynamic_dropdown
          Parent Dropdown: tsRegion
          dddx Group: townsselector
          first row text: -- choose District --
          where:
          {"region_id":"[[+tsRegion]]"}

          packagename: townsselector
          classname: tsDistrict
          idfield: id
          namefield: district

          name: tsTown
          input type: dynamic_dropdown
          Parent Dropdown: tsDistrict
          dddx Group: townsselector
          first row text: -- choose Town --
          where:
          {"district_id":"[[+tsDistrict]]"}

          packagename: townsselector
          classname: tsTown
          idfield: town
          namefield: town
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 36970
            • 23 Posts
            It's working great. Many thanks. Can I now just copy package files to live website and create tables and everything in PHPMyAdmin or have I create it via MIGXdb again?
              • 4172
              • 5,888 Posts
              should be enough to copy your files to the live-site and create your tables there.
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 36970
                • 23 Posts
                I have it on live page now and everything works it only have a small problem. it outputs id of district and id of region instead of its name when I want to show it on page [ed. note: blueeyeddevil last edited this post 11 years, 6 months ago.]
                  • 4172
                  • 5,888 Posts
                  this realy is only a small problem.

                  with this snippet, name it getDbField:

                  $packagname = $modx->getOption('packagename', $scriptProperties, '');
                  $classname = $modx->getOption('classname', $scriptProperties, '');
                  $returnfield = $modx->getOption('returnfield', $scriptProperties, '');
                  $output = '';
                  
                  if (!empty($classname)) {
                      if (!empty($packagename)) {
                          $modx->addPackage($packagename, $modx->getOption('core_path') . 'components/' . $packagename . '/model/');
                      }
                  
                      unset($scriptProperties['packagename'], $scriptProperties['classname'], $scriptProperties['returnfield']);
                  
                      $c = $modx->newQuery($classname);
                  
                      foreach ($scriptProperties as $searchfield => $value) {
                          $c->where(array($searchfield => $value));
                      }
                  
                      if ($object = $modx->getObject($classname, $c)) {
                          $output = $object->get($returnfield);
                      }
                  }
                  
                  
                  return $output;
                  


                  you can get every field-value with something like that:

                  tsDistrict: [[getDbField? &packagename=`townsselector` &classname=`tsDistrict` &returnfield=`district` &id=`[[*tsDistrict]]`]] 
                  
                  tsRegion: [[getDbField? &packagename=`townsselector` &classname=`tsRegion` &returnfield=`region` &id=`[[*tsRegion]]`]] 
                   
                  
                  [ed. note: Bruno17 last edited this post 11 years, 6 months ago.]
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 36970
                    • 23 Posts
                    I think this code is missing $id variable because it is always returning first region and first district in table.
                      • 36970
                      • 23 Posts
                      OK I fixed it. So the snippet code look like:

                      $packagname = $modx->getOption('packagename', $scriptProperties, '');
                      $classname = $modx->getOption('classname', $scriptProperties, '');
                      $returnfield = $modx->getOption('returnfield', $scriptProperties, '');
                      $id = $modx->getOption('id', $scriptProperties, '');
                      $output = '';
                       
                      if (!empty($classname)) {
                          if (!empty($packagename)) {
                              $modx->addPackage($packagename, $modx->getOption('core_path') . 'components/' . $packagename . '/model/');
                          }
                       
                          unset($scriptProperies['packagename'], $scriptProperies['classname'], $scriptProperies['returnfield']);
                       
                          $c = $modx->newQuery($classname);
                       
                          foreach ($scriptProperties as $searchfield => $value) {
                              $c->where(array('id' => $scriptProperties['id'],));
                          }
                       
                          if ($object = $modx->getObject($classname, $c)) {
                              $output = $object->get($returnfield);
                          }
                      }
                       
                       
                      return $output;
                      


                      And this way it works perfect. Thank you very much.