0

I retrieve data from database using this query:

SELECT * FROM tickets_departement_groups WHERE group_id = '{$user_group}'

$user_group is already defined, and I fetch the data using mysql_fetch_array, like this:

foreach ($query->result_array() as $row)
{
    return $row['departement_id'];
}

All this is under a function called get_departement_id(), So when I do echo get_departement_id(); it prints last departement ID, but I have many of them. What I want to do is to output all the department IDs for a given query.

3
  • It's spelt "department". Commented Mar 31, 2011 at 18:44
  • I couldn't help but notice that as well. Must be the GUI programmer in me, but I resisted commenting (until now). :) Commented Mar 31, 2011 at 18:53
  • @Sam: Hehe your resistance is better than mine. Mine appears to be ... well, futile. Commented Mar 31, 2011 at 23:13

1 Answer 1

3

create and array and return the array?

$id_list = array();
foreach($query->result_array()  as $row){
    $id_list[] = $row['departement_id'];
}

return $id_list;
Sign up to request clarification or add additional context in comments.

1 Comment

This sounds like the most flexible solution. This allows the caller to do whatever it wants with the data rather than narrowing it to just printing (unless that is the only purpose...).

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.