We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3504
    • 11 Posts
    I’m using a TV where you can enter the name of a city for some courses and I’m listing in a table the courses with Ditto.

    I want to have a select input which I will use to filter the courses by city, etc . The thing is that I want to populate the options on the select input dynamicaly. There is a way to get ALL the data entered in that specific TV and listed without duplicating the values itself?

      • 4310
      • 2,310 Posts
      A snippet something like this where 21 is the ID of your "city" TV :
      <?php
      $output .='<select name="city">';
      $output .='<option value="">Please select City</option>';
      $result = $modx->db->query('SELECT DISTINCT `value` FROM `modx_site_tmplvar_contentvalues` WHERE `tmplvarid` = 21 ORDER BY `value` ASC');
      $cities = $modx->db->makeArray( $result ); 
      foreach($cities as $city){
      $output .='<option value="'.$city['value'].'">'.$city['value'].'</option>'."\n";
      }
      $output .='</select>';
      return $output;
      ?>

        • 3504
        • 11 Posts
        This is great! Thank you so much!