1

At the moment I have this code:

$divisions = explode(",", $mychecklist->dept);

foreach($divisions as $division) {
    $divs=get_record('induction_emails','id',$division);
    $useremail = get_record('user', 'email', $divs->email);
    echo $useremail->id;
}

This basically gets the division id from induction emails table, then checks the users table to match email to user. The final result I want is the user id's.

Once I have the user id's I want to put them into an array.

Any help would be appreciated. Thanks in advance.

1
  • imho, this is a bad design, if the get_record involve DB query, you won't like to iterate/repeatedly query database to get single record, reconstruct the function design to allow single query-->fetch all-->return the array Commented Aug 9, 2011 at 11:06

4 Answers 4

5
$divisions = explode(",", $mychecklist->dept);
$users = array();
foreach($divisions as $division) {
    $divs=get_record('induction_emails','id',$division);
    $useremail = get_record('user', 'email', $divs->email);
    echo $useremail->id;
    $users[] = $useremail->id;
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can use the following:

$divisions = explode(",", $mychecklist->dept);
$ids = array();
foreach($divisions as $division) {
    $divs=get_record('induction_emails','id',$division);
    $useremail = get_record('user', 'email', $divs->email);
    $ids[] = $useremail->id;
}
print_r($ids);

1 Comment

thanks, i had tried $ids[] = $useremail->id; but did not do $ids = array(); This works great, cheers
0

Arrays are explained here, together with some examples. In short:

$user_ids = array();
foreach(...){
    ...
    $user_ids[] = $useremail->id;
}

Comments

0

Here is some pseudocode for using the foreach statement:

$users=array();

foreach(..) {
    ...
    $users[]=$useremail->id;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.