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?

$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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.