ActiveRecord,Querying and For Loops

Hi there!

I have a question about for loops and Active Record and querying.

I have this code below that uses id stored in session and it is used to query for the users’ first names.


The first half of the code is working, where it is able to get the first name and populate $usernames.

But the second half of the code, in the For Loop, $thisuser does not become an object, and i get the error of "Trying to get property of non-object".

I know that $session[‘user’.$j] works, and that the for loop works if i put in $session[‘user1’] instead. I’ve even tried re-initializing $thisuser in each loop, but there is no difference.

What am I missing?

I understand that putting it all into an array would be better than having 5 variables, but this might become a problem when i make the switch later on.

Thank you!!

findOne returns null if it can not find a record:

Thus whatever “$session[‘user’ . $j]” returns, it is not a key found in the database.

Thanks! Guess I will have to find a work around.

Checking whether "$thisuser" is null before using it would be good practice.