glennn.php Posted May 5, 2008 Share Posted May 5, 2008 ok, i checkboxes whose values might be any array of integers (1, 6, 14)... with "1" meaning "Dog", 6 meaning "Elephant", "14" meaning "Wife", etc., i need to echo a name for each selected checkbox (i cannot change the values of them)... having this: for($x=0; $x<count($category); $x++) { $exp= $category[$x]; echo $exp[0] . '<br />'; // output each selected category } could someone show me how i might convert the "1" to "Dog", etc...? thanks much, GN Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 5, 2008 Share Posted May 5, 2008 $checkboxlist = array(1=>"Dog", "Giraffe", "Cow", "Pig", "Farmer", "Elephant" .... "Wife"); foreach ($_POST['category'] as $k=>$v) { echo $checkboxlist[$k]; } >_> I put one as the first key so it corresponds to the form. Quote Link to comment Share on other sites More sharing options...
glennn.php Posted May 5, 2008 Author Share Posted May 5, 2008 almost ... having 15 possible selections, no matter which ones i select i get "DogGiraffeCow"... (the first three - i can handle the line breaks once i get the right values converted...) hhmmm.... Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 5, 2008 Share Posted May 5, 2008 Uhh....are you putting in the correct POST variable and do you have the checkboxes as an array? <input type="checkbox" name="category[]">1 Etc. Quote Link to comment Share on other sites More sharing options...
glennn.php Posted May 5, 2008 Author Share Posted May 5, 2008 yes, it's an array --- name="category[]" --- Quote Link to comment Share on other sites More sharing options...
glennn.php Posted May 5, 2008 Author Share Posted May 5, 2008 name="category[]" value="1">Dog name="category[]" value="2">Cat name="category[]" value="3">Giraffe Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 5, 2008 Share Posted May 5, 2008 print_r($_POST); Do that for me AFTER sending for data and show me the output. Quote Link to comment Share on other sites More sharing options...
glennn.php Posted May 5, 2008 Author Share Posted May 5, 2008 Array ( [0] => 3-Cardiovascular Pathology [1] => 4-Cytopathology [2] => 7-Gastrointestinal Pathology [3] => 9-Gynecological Pathology ) i have to take the "-Cardiovascular Pathology" out of the db inserts and just use ints... Quote Link to comment Share on other sites More sharing options...
glennn.php Posted May 5, 2008 Author Share Posted May 5, 2008 in other words i need: [0] => 3 [1] => 4 [2] => 7... and then the "3" echoed as "Cardiovascular Pathology", etc... CAN'T have the checkboxes containing the values they do now... Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 5, 2008 Share Posted May 5, 2008 Okay, so take the names of the categories OUT of the checkboxes and use this: $checkboxlist = array(1=>"Dog", "Giraffe", "Cow", "Pig", "Farmer", "Elephant" .... "Wife"); foreach ($_POST['category'] as $k=>$v) { echo $checkboxlist[$v]; } I used the wrong variable last time. Remember, take the other part out and just leave the number. Quote Link to comment Share on other sites More sharing options...
glennn.php Posted May 5, 2008 Author Share Posted May 5, 2008 right, that's what i'm having to do (they were in there for this reason, to echo the name after exploding() the 1 and the name, but it was causing issues elsewhere; i'll try this and say thanks to ya. Quote Link to comment Share on other sites More sharing options...
glennn.php Posted May 5, 2008 Author Share Posted May 5, 2008 amen, thanks much DW... Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 5, 2008 Share Posted May 5, 2008 No problem. Quote Link to comment 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.