# MYSQL Result Hash Problem

**URL:** <https://www.ruby-forum.com/t/mysql-result-hash-problem/193718>\
**Category:** Rails\
**Created:** [August 23, 2010, 9:28am UTC](https://www.ruby-forum.com/t/mysql-result-hash-problem/193718 "2010-08-23T09:28:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudheendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e0b2c6/32.png) [@sudheendra](https://www.ruby-forum.com/u/sudheendra)\
**Post date:** [August 23, 2010, 9:28am UTC](https://www.ruby-forum.com/t/mysql-result-hash-problem/193718/1 "2010-08-23T09:28:02Z")

</div>

Hi,

Is there any way to iterate through MySQL Result Hash multiple times ?

Current Problem: After One iteration, second iteration no records.

Need your help at the earliest.

Regards,  
Sudheendra

---

<div class="post-metadata">

**Author:** ![sudheendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e0b2c6/32.png) [@sudheendra](https://www.ruby-forum.com/u/sudheendra)\
**Post date:** [August 23, 2010, 9:34am UTC](https://www.ruby-forum.com/t/mysql-result-hash-problem/193718/2 "2010-08-23T09:34:28Z")

</div>

On 23 August 2010 08:28, Sudheendra P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi,
> 
> Is there any way to iterate through MySQL Result Hash multiple times ?
> 
> Current Problem: After One iteration, second iteration no records.

If you post the code you’re having a problem with, then maybe we can  
make some suggestions.

Ideally, the smallest sample of the code that exhibits the problem  
you’re experiencing so the model query and the loop should suffice.

---

<div class="post-metadata">

**Author:** ![sudheendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e0b2c6/32.png) [@sudheendra](https://www.ruby-forum.com/u/sudheendra)\
**Post date:** [August 24, 2010, 2:18am UTC](https://www.ruby-forum.com/t/mysql-result-hash-problem/193718/3 "2010-08-24T02:18:51Z")

</div>

Michael P. wrote:

> On 23 August 2010 08:28, Sudheendra P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Hi,
> > 
> > Is there any way to iterate through MySQL Result Hash multiple times ?
> > 
> > Current Problem: After One iteration, second iteration no records.
> 
> If you post the code you’re having a problem with, then maybe we can  
> make some suggestions.
> 
> Ideally, the smallest sample of the code that exhibits the problem  
> you’re experiencing so the model query and the loop should suffice.

Here goes the code

journal\_details = conn.dbconnection.query(  
“SELECT value,prop\_key from Journal\_Details  
INNER JOIN journals on journals.id = journal\_details.id  
WHERE journalized\_id = ‘#{issue\_id}’ and  
Date(created\_on)=‘#{date}’ ORDER By journals.id”  
)

#The above is the query which results few records

journal\_details.each\_hash do |journal\_details\_record|

# Do some processing

end

journal\_details.each\_hash do |journal\_details\_record|

# I need to do reuse the query here so that i can do some other

processing.

# But this loop will not come inside

# I am thinking if there is any EOF kind of thing has been reached.

# And i do not know how to reset the pointer to point first record

end

Also I have tried with each method instead of each\_hash. Same problem  
continues.

Thank in advance for your help
