One sec....
you want to show stored values in html right?
like:
"User A selected Fruits and prefers Apples"
in that case you should use a helper function to get the text for the number value from the db.
Some thing like i do. I have class named DB_helper which holds functions like that.
function get_link_table_values($val, $table, $key_fld, $val_fld, $link_type, $list_format=0) {
$out = '';
if( $link_type=='single' ) {
$cmd= "SELECT $val_fld FROM $table WHERE $key_fld=$val";
$row = $this->getRecords($cmd);
if( count($row)!=0 )
$out = $row[0][0];
}
else {
if( trim($val)!='' ) {
$vals = explode(',',$val);
$cmd= "SELECT $val_fld FROM $table WHERE";
if( count($vals)!=0 ) {
for($i=0;$i<count($vals); $i++ ) {
$cmd .= " $key_fld=".$vals[$i];
$cmd .= ' OR ';
}
$cmd = substr($cmd,0,strlen($cmd)-4);
$rows = $this->getRecords($cmd);
if( count($rows)!=0 ) {
for($i=0;$i<count($rows); $i++ ) {
if( $list_format==0 ) {
$out .= '- '.$rows[$i][0].'<br>';
}
else {
if( $out!='' )
$out.=',';
$out .=$rows[$i][0];
}
}
}
}
}
}
return($out);
} // ----------------------------------------------------------------
$val = selected value
$table = db table
$key_fld = key field, the number in our case
$val_fld = the field with the text
$link_type = 'single' or 'multi', if you want to get many values from the table, comma separated
$list_format= 0 or 1, if 0 returns the results like
- Text text <br>
- Text text <br>
.....
if 1 comma separated.
for a single value stored in a table named food with columns food_id, food_description
to get food_id=12, call it like
echo get_link_table_values(12, 'foods', 'food_id', 'food_description', 'single', 0);