Set string of array id in to array of field id values

Hi there,

i have a database field with comma separated id values. the id are all linked to a value in another table

something like
op_id
21,23,45,8034,12,45

now i want to show the values, not the id in another field comma seperated, say the field classes

so i explode the op_id make an array and implode it into the values but somewhere on the way i dont’ get a comma separated values in a field. any suggestions?

Need to see your code to answer your question

// sets the field with the array (double select) om in string
$klascode_totaal = array({wk_op_id_koppel});

foreach ($klascode_totaal as $op_id)

{

/**

  • Selecting a field from another table
    */

// Check for record
$check_sql = “SELECT op_klascode”
. " FROM project_opleidingen"
. " WHERE op_id = ‘" . $op_id . "’";
sc_lookup(rs, $check_sql);

if (isset({rs[0][0]})) // Row found
{
{klascode} = {rs[0][0]};

}
else // No row found
{
{klascode} = ‘’;

}

$result = {klascode};

}

//
$mystring = implode(",",$result);

{KLASCODE} = $mystring;

You should replace

$result = {klascode};

with

$result[] = {klascode};

if you are using MySQL you can use GROUP_CONCAT to do it

SELECT GROUP_CONCAT(klas ORDER BY klas SEPARATOR ‘,’) as klascode FROM table WHERE op_id IN ({wk_op_id_koppel})

2 Likes

Thanks again. i tried both and they work perfectly. sometimes in scriptcase i’m a bit lost where to put what because the result is not always what it should be