# Storing data from database into array

**URL:** <https://www.ruby-forum.com/t/storing-data-from-database-into-array/107722>\
**Category:** Rails\
**Created:** [June 25, 2007, 6:32pm UTC](https://www.ruby-forum.com/t/storing-data-from-database-into-array/107722 "2007-06-25T18:32:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nekapoor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ea666f/32.png) [@nekapoor](https://www.ruby-forum.com/u/nekapoor)\
**Post date:** [June 25, 2007, 6:32pm UTC](https://www.ruby-forum.com/t/storing-data-from-database-into-array/107722/1 "2007-06-25T18:32:09Z")

</div>

Hello,

I don’t know what the Rails multidimensional array structure is and I am  
having a problem in this regard.

Basically we have a set of games and in a XMLFEEDS table we have basic  
information about the games (the game date, the sport type of the game).  
Then in the PARTS table, we have two entries per xmlfeed entry which  
correspond to the two teams participating in the game.

Essentially, right now I have a line in my code that goes like this:  
@local\_lines1 = Xmlfeed.find(:all, :conditions =\> [“id = ?”, @id])

This is guaranteed to give me exactly one row from the database and as  
such, am able to make a call like this:

@visiting\_team = @local\_lines1[0].parts[1].participant\_name

where the xmlfeeds table and the parts table have been linked in a model  
somewhere. I am able to just reference the zeroth element of the  
@local\_lines1 variable since I know that there is only 1 row that is  
being selected from the database call.

But now I want to store all of the data from the xmlfeed in a session  
variable so I do this:

session[:lines] = Xmlfeed.find(:all);

But this now should be a multidimensional array of data since there are  
multiple rows being selected.

My question is, how do I again get that row that corresponds to the @id  
variable so that i can access all data corresponding to that row?

I have tried simply doing this:  
@local\_lines1 = session[:lines].select {|record| record.id == @id}

which I think should give me the one row that I want, but then when I  
try to access, for example, the visiting them the way I previously tried  
(i.e. @local\_lines1[0].parts[1].participant\_name), my application fails.

I hope this wasn’t too confusing! If anyone has any ideas, I would  
greatly appreciate it.

Thank you so very much ahead of time for your help.
