jymick Posted July 7, 2009 Share Posted July 7, 2009 Hi,My site proposes a form of registrationThe field "color" proposes checkboxes with multiple choices.If the user during his registration marks the blue checkbox, then in its profile the image blue.gif is going to display correctly.If the user marks the blue and red checkboxes, in its profile the code asks me for the image bluered.gifNow I would like that the code shows me images blue.gif and red.gif.Here's my code:$Color= _t("Color").": "._t($aPreValues['Color'][$p_arr['Color']]['LKey']).' <img src="'. ($site['img'].strtolower($p_arr['Color'])) .'.gif" alt="Color" />'; Thank you Link to comment Share on other sites More sharing options...
justsomeguy Posted July 7, 2009 Share Posted July 7, 2009 What is the code you have for the checkboxes and how do you process the form? How do you save that data? Link to comment Share on other sites More sharing options...
jymick Posted July 7, 2009 Author Share Posted July 7, 2009 What is the code you have for the checkboxes and how do you process the form? How do you save that data?Each checkboxe are in a sql table Link to comment Share on other sites More sharing options...
justsomeguy Posted July 7, 2009 Share Posted July 7, 2009 Checkboxes aren't in a SQL table, they're in an HTML form. I assume that you're storing one value for each checkbox in the database, right? As opposed to all the values in one place. So, you should be able to get the user's record from the database and loop through each checkbox to display the image. What I don't understand is how this:($site['img'].strtolower($p_arr['Color']))comes to be "redblue" instead of having only a single value. You should have an array of colors to loop through and display each one, why are the different colors part of the same value? Link to comment Share on other sites More sharing options...
jymick Posted July 7, 2009 Author Share Posted July 7, 2009 Checkboxes aren't in a SQL table, they're in an HTML form. I assume that you're storing one value for each checkbox in the database, right? As opposed to all the values in one place. So, you should be able to get the user's record from the database and loop through each checkbox to display the image. What I don't understand is how this:($site['img'].strtolower($p_arr['Color']))comes to be "redblue" instead of having only a single value. You should have an array of colors to loop through and display each one, why are the different colors part of the same value?If i want display text without image here s the code:$Color= _t("Color").": ".process_line_output($p_arr['Color']);It will display:Color : blue (1 checkbox)Color : blue,red (2 checkboxes) Link to comment Share on other sites More sharing options...
justsomeguy Posted July 7, 2009 Share Posted July 7, 2009 Well, I'm not sure what your _t or process_line_output functions are doing, but if you have a comma-separated list of colors in either the $p_arr['Color'] variable or from the process_line_output function, you can use the explode function to split the comma-separated list into an array, and then loop through the array and output one image tag (or whatever you want to output) for each item in the array.http://www.php.net/manual/en/function.explode.php Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.