iterate and echo array elements

Hi,

I have an in dex method with a find to select all distinct user id's in my user table;

$userId = $this->Order->find('all', array('fields'=>array('DISTINCT(Order.user_id) AS user')));

which sends back the lovely array:

[userId] => Array([0] => Array([Order] => Array([user] => 4)

[userId] => Array([1] => Array([Order] => Array([user] => 5) etc etc.

Now I need to echo those user id's in index.ctp on separate lines. The reason im not using the normal echo $order[Order][user_id] is because there are multiple entries for each user id and i only want distinct values.

Hope that makes sense...

Asked by jamesl, on 8/2/10

1 Answer

you did not really ask a question there.

you will just need to use a foreach loop like normal, and if you dont know what the keys are just debug inside the foreach loop

Answered by dogmatic69on 8/2/10

Hi dogmatic thanks for that.

my question is really how to best display the data. I tried to use a foreach to loop through but it was displayed as:

4 3 5

4 3 5

4 3 5

etc with all the vlaues from the userId field echod on each line. What am I missing?

jamesl - on 8/2/10

<< comments | comments >>
<< previous next >>

Your Answer

You can use Creole Wiki Syntax to format your text.

Tagged with

Rating

0

Viewed

407 times

Last Activity

on 8/2/10