Jump to content

attaching a name to a number - (i.e., help)


glennn.php

Recommended Posts

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
Share on other sites

$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
Share on other sites

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
Share on other sites



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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.