Jump to content

numbered array in database, need to show as text


jarv

Recommended Posts

hi,

 

on my site I have 6 checkboxes:

 

Box1 = Internet

Box2 = Yellow pages

Box3 = Van

Box4 = Letting agent

Box5 = Repeat customer

Box6 = Recommendation

 

which ever is checked they go into the database as a number, for example, if all were checked I get 0|1|2|3|4|5 in my database.

 

This all works fine but, I need to show which are checked, if my database had: 0|2|4

I need it to say: Internet, Van, Repeat Customer

 

please help?

Link to comment
Share on other sites

$names = array('Internet','Yellow pages','Van','Letting agent','Repeat customer','Recommendation');
// assuming you have a var called $dbValues with the results from database and that it looks like this: 0|1|3
$dbNumbers = explode("|",$dbValues);
$n = array();
foreach($dbNumbers as $num){
   $n[]=$names[$num];
}
echo implode(", ",$n);

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.