We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24969
    • 120 Posts
    Ok. I know how to do this, but I need to do it in a way that will pull the names from a database to populate the list boxes, then based on the selection it will take the ’id’ of the selected name and pull the image value form the database.

    I thing I have a handle on creating the list boxes, but I have no idea how to call the second select statement passing it the ’id’ value.

    tblnames
    id value
    1 Greg
    2 Norman
    3 Jane
    4 Lori
    5 Susan

    Based on the selected name above, I can select the appropriate image recode from the table below, I just need to know how to do this?
    huh huh
    tblimages
    id filelocation name_fk
    1 /images/... 5
    2 /images/... 2
    3 /images/... 1
    4 /images/... 3
    5 /images/... 4
      The important thing is not to stop questioning. Curiosity has its own reason for existing. One cannot help but be in awe when he contemplates the mysteries of eternity, of life, of the marvelous structure of reality. It is enough if one tries merely to comprehend a little of this mystery every day. Never lose a holy curiosity.

      -Albert Einstein (1879 - 1955)

      Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8e-fips-rhel5 DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Do both at the same time. Have the value of the option be the image ID, and the text be the individual’s name. Then when one is selected, you already know which image to display or whatever.

      When processing the submission of the form, get the image data from the database using the POST value from the select. Or simplify things by having the images in one place, and you only need to know the filename; that can be the value, so you know to get /images/$_POST[’image’].jpg; this way you avoid another query to the database.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 24969
        • 120 Posts
        OK... I’m not sure I know how to create the ddlbox... I’ve tried to create one with the following code;
        llbstart
        <select name="menu" >
        	<option>Please Select</option>

        to start the listbox...
        then I have some dynamic data
        goldenmale
         <option>[+callname+]</option>

        then I have to close out the listbox
        lbfinish
        </select>


        so on my page I have
        [[llbstart]]
        [[goldenmale]]
        [[lbfinish]]

        I know this will not be the finished product, I just want to get a listbox with data init first.

        How do you create a list box?
          The important thing is not to stop questioning. Curiosity has its own reason for existing. One cannot help but be in awe when he contemplates the mysteries of eternity, of life, of the marvelous structure of reality. It is enough if one tries merely to comprehend a little of this mystery every day. Never lose a holy curiosity.

          -Albert Einstein (1879 - 1955)

          Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8e-fips-rhel5 DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
          • 10487 MODX Staff
          • 1,535 Posts
          Untested, but shouldn’t be too far off - create a snippet called ddlist (or whatever you want) and paste this in:
          $output = '<select name="menu"><option>Please Select</option>';
          $rs = $modx->db->query('SELECT `n`.`value`, `i`.`filelocation` FROM `tblnames` AS n INNER JOIN `tblimages` AS i ON `n`.`id` = `i`.`name_fk`;');
          if ($modx->db->getRecordCount($rs) > 0) {
          	while ($row = $modx->db->getRow($rs)) {
          		$output .= '<option value="' . $row['filelocation'] . '">' . $row['value'] . '</option>';
          	}
          }
          $output .= '</select>';
          return $output;
          

          Call the snippet uncached so you always get the most-to-date data from the tables:
          [!ddlist!]

          Hope that helps get you going smiley
            Garry Nutting
            Senior Developer
            MODX, LLC

            Email: [email protected]
            Twitter: @garryn
            Web: modx.com
            • 24969
            • 120 Posts
            Thank you so much Gary... It is so nice when you pose a question to the group and you receive a reply with a working solution.... Thank you again.
            It will come in handy wink
              The important thing is not to stop questioning. Curiosity has its own reason for existing. One cannot help but be in awe when he contemplates the mysteries of eternity, of life, of the marvelous structure of reality. It is enough if one tries merely to comprehend a little of this mystery every day. Never lose a holy curiosity.

              -Albert Einstein (1879 - 1955)

              Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8e-fips-rhel5 DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635