Populate an array with record ID's that match certain criteria (Select, Where)

Hi There,

is there an easy way to create a select where that populates an array (comma separated) with the ID’s of the records that match the criteria?

With group_concat() in your sql select you can group all the records (as defined by your where clause) of a specific field using any separator you want

Hi robdago. thanks for the reply.

that did the trick!

for all those that search the same answer.

just curious, now it is comma sepearted, how can i change this to: for example ;

// Check for record
$check_sql = “SELECT GROUP_CONCAT(wk_id)”
. " FROM ILP_rooster_TEMP"
. " WHERE ev_id = ‘82’"
. " ORDER BY ronde_id";
sc_lookup(rs, $check_sql);

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

}
else // No row found
{
$test = ‘’;

}

echo $test;

MySQL | Group_CONCAT() Function - GeeksforGeeks

with replace function you can do it:
SELECT REPLACE(GROUP_CONCAT(wk_id), ‘,’,’;’)

GROUP_CONCAT has three parameters:

  • Distinct: It eliminates the repetition of values from result.
  • Order By: It sort the values of group in specific order and then concatenate them.
  • Separator: By default, the values of group are separated by (, ) operator. In order to change this separator value, Separator clause is used followed by a string literal. It is given as Separator ‘str_value’.

See this link for details:

great, thanks all! this is much help-full. sometimes in Scriptcase things works just a little bit different