0

I need to grab data from a symfony 2 db. The data looks like :

Parent-Element [id 15]
 -> Child Element [id 20, parent ID 15]
 --->Child Element [id 27, parent ID 20]
 ----->Child Element [id 34, Parent ID 27]
 ....

The Childs are assigned to each parent Element by a cathegory ID see [ ]. There might be more than one Child Elements per level.

In php it would be easy to grab this by a while loop. But in Symfony im stucking. Can anyone help me finding a solution? IS there a while loop in symfony?

Kind regdards

Philipp

EDIT: I mean, in "normal" php I would do a simple while or create an array with ids which I loop through by another while loop... In smyfony, I would use a queryBuilder like that

$query = $em->createQueryBuilder()
    ->select('d')
    ->from('PrUserBundle:Location', 'd')
    ->where('d.client_id = :client_id')
    ->setParameter('client_id', $this->clientId)
    ->getQuery();
    $results=$query->getResult();

Where I don't see any possibility to grab any other Ids or sort it so that I can render a parent-child listing.

1
  • 1
    Uhm, Symfony is PHP, you can use while loops all you want. Could it be that your question is rather aimed at the difference between retrieving results in plain MySQL and retrieving results in Doctrine/DQL? If so, please clarify. Commented Sep 2, 2014 at 9:57

1 Answer 1

1

What about iterators:

$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($array));
foreach($iterator as $key => $value) {
    echo "$key => $value\n";
}
Sign up to request clarification or add additional context in comments.

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.