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 Link to comment https://forums.phpfreaks.com/topic/104279-attaching-a-name-to-a-number-ie-help/ 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. Link to comment https://forums.phpfreaks.com/topic/104279-attaching-a-name-to-a-number-ie-help/#findComment-533876 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.... Link to comment https://forums.phpfreaks.com/topic/104279-attaching-a-name-to-a-number-ie-help/#findComment-533890 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. Link to comment https://forums.phpfreaks.com/topic/104279-attaching-a-name-to-a-number-ie-help/#findComment-533900 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[]" --- Link to comment https://forums.phpfreaks.com/topic/104279-attaching-a-name-to-a-number-ie-help/#findComment-533909 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 Link to comment https://forums.phpfreaks.com/topic/104279-attaching-a-name-to-a-number-ie-help/#findComment-533915 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. Link to comment https://forums.phpfreaks.com/topic/104279-attaching-a-name-to-a-number-ie-help/#findComment-533917 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... Link to comment https://forums.phpfreaks.com/topic/104279-attaching-a-name-to-a-number-ie-help/#findComment-533928 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... Link to comment https://forums.phpfreaks.com/topic/104279-attaching-a-name-to-a-number-ie-help/#findComment-533936 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. Link to comment https://forums.phpfreaks.com/topic/104279-attaching-a-name-to-a-number-ie-help/#findComment-533940 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. Link to comment https://forums.phpfreaks.com/topic/104279-attaching-a-name-to-a-number-ie-help/#findComment-533943 Share on other sites More sharing options...
glennn.php Posted May 5, 2008 Author Share Posted May 5, 2008 amen, thanks much DW... Link to comment https://forums.phpfreaks.com/topic/104279-attaching-a-name-to-a-number-ie-help/#findComment-533949 Share on other sites More sharing options...
DarkWater Posted May 5, 2008 Share Posted May 5, 2008 No problem. Link to comment https://forums.phpfreaks.com/topic/104279-attaching-a-name-to-a-number-ie-help/#findComment-533951 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.