cjenkins08 Posted April 27, 2014 Share Posted April 27, 2014 I'm pretty new to PHP, but I am wondering what would be the easiest way to accomplish this. I am looking to have a form with two different lists(each list will have the name of one of the 50 states), the user will be able to select one state from each list. Each state on the list will have a picture of the state that is accociated with it. What is the easiest way to connect the name chosen with the image associated with it? Should this be in a Database? Should the images be stored direct or via a link to the URL of the images? Could the images just be stored in an Array? Using FPDF I have already styled a page, then I am then going to display the two state images in that same .pdf file. Quote Link to comment https://forums.phpfreaks.com/topic/288063-php-form-and-images/ Share on other sites More sharing options...
Ch0cu3r Posted April 27, 2014 Share Posted April 27, 2014 (edited) What is the easiest way to connect the name chosen with the image associated with it? Give each image the name of the state. eg Alabama.png, Ohio.png etc. You'd set up your dropdown menu like State: <select name="state"> <option>Alabama</option> <option>Alaska</option> <option>Arizona</option> ... <option>Wyoming</option> </option> You'd then link to the image using something like this if(isset($_POST['state'])) { // load the state images stored in site.com/images/states into an array $state_images = glob('images/states/*.png'); // get the associated image if(in_array($_POST['state'] . '.png', $state_images)) { $state_image_path = '/images/states/'.$_POST['state'].'.png'; } // display the associated image echo 'State Selected: ' . $_POST['state'] . '<br />State Image: <img src="'.$state_image_path.'" />'; } Edited April 27, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/288063-php-form-and-images/#findComment-1477454 Share on other sites More sharing options...
cjenkins08 Posted April 27, 2014 Author Share Posted April 27, 2014 Thank you for the reply. Looks easy enough, I will give this a try. Quote Link to comment https://forums.phpfreaks.com/topic/288063-php-form-and-images/#findComment-1477455 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.