6 Replies Latest reply: Nov 23, 2012 5:43 AM by David_Powers RSS

    Adding a passed parameter to a image pathway

    Smohren

      I am using dreamweaver CS5 and I have a web page that passes a 4 letter code to another web page that contains images.  I want to include the 4 letter code in the pathway of the image shown on the web page, is this possible?

       

      For example, lets say a person uses a pick list and picks "TFFA" and hits submit.  TFFA is passed to another web page.  All of this works fine.  Now what I want to do is add "TFFA" to the pathway for the image.  So in the example below you will see TFFA is actually part of the image name.  All of the images are named the same with the exception of the first 4 letters which is dependent on the value a person picks from the previous web page.

       

      Thanks

       

       

       

      <li>

                            <span class="style16">Point 01</span><a href="images/TFFA01_2009.jpg" title=""><img src="TFFA01_2009_Thumb.jpg" width="160" height="106" alt="Flower" /></a>

                          </li>

        • 1. Re: Adding a passed parameter to a image pathway
          sudarshan.t MVP

          Now what I want to do is add "TFFA" to the pathway for the image.

          Can you please be more descriptive? I don't quite understand 'pathway for the image' bit.

          • 2. Re: Adding a passed parameter to a image pathway
            John Waller MVP

            I took it to mean that the OP wants a variable in the image path to dynamically alter the path name depending on the option selected in the pick list.

             

            Selecting TFFA would modify the path in the code as

             

            <a href="images/TFFA01_2009.jpg" title=""><img src="TFFA01_2009_Thumb.jpg" width="160" height="106" alt="Flower" /></a>

             

            Selecting TFFB would modify the path in the code as

             

            <a href="images/TFFB01_2009.jpg" title=""><img src="TFFB01_2009_Thumb.jpg" width="160" height="106" alt="Flower" /></a>

             

            Easily done with PHP



            • 3. Re: Adding a passed parameter to a image pathway
              Smohren Community Member

              Sorry Sudarshan,

               

              I think John below has it correct but I did not understand the example provided.  I am really looking for someone to show me how to write the path name for an image when it included a passed parameter.

               

              As an example, lets say the pathway to where all the images are located is:  C:\monitoring\

               

              and there are three images, LAVO_2009, CRLA_2009, and LABE_2009.

               

              So depending on what code the person picks (LAVO, CRLA, or LABE), the pictures shown on the page will be different.  It will either be:  C:\monitoring\LAVO_2009, C:\monitoring\CRLA_2009, or C:\monitoring\LABE_2009. 

               

              Hope this helps

              • 4. Re: Adding a passed parameter to a image pathway
                sudarshan.t MVP

                Do you only have a limited number of images or do you have many of them? The reason I ask - if you have only a limited number of them, you could do a string validation and pass that to the page which will load the image. If you have way too many of them, you should ideally consider building a control panel to ensure there are no errors that arise in the long term.

                 

                BTW, I'm moving this thread to 'Developing server-side applications in Dreamweaver' for better responses.

                 

                -ST

                • 5. Re: Adding a passed parameter to a image pathway
                  Smohren Community Member

                  There are ~150 pictures, but the page only displays 15 pictures depending on what code is picked (15 pictures per code with 10 possible codes).  I am pretty new to this and I am not sure what you mean by "building a control panel"

                   

                  Thanks for the help.

                  • 6. Re: Adding a passed parameter to a image pathway
                    David_Powers ACP

                    As John says, this is easily done with PHP. To ensure that the value passed through the URL is valid (and not an attempt to probe the file system), you would need to create an array of acceptable values at the top of the page. Assuming the variable is passed on the end of the URL as ?cat=TFFA (or whatever value is chosen), it would look like this:

                     

                    <?php

                    $valid = array('TFFA', 'LAVO', 'CRLA', 'LABE');

                    if (in_array($_GET['cat'], $valid)) {

                        $prefix = $_GET['cat'];

                    } else {

                        $prefix = 'TFFA';

                    }

                    ?>

                     

                    This checks whether the value passed through the URL is in the $valid array. If it is, it's assigned to $prefix. If it's not, $prefix is given a default value to prevent errors.

                     

                    Then, in the body of the page, the value of $prefix is used like this:

                     

                    <a href="images/<?php echo $prefix; ?>01_2009.jpg" title=""><img src="<?php echo $prefix; ?>01_2009_Thumb.jpg" width="160" height="106" alt="Flower" /></a>