From: luke gruber Date: 2011-10-16T12:43:15+09:00 Subject: Re: Ruby and MySQl It looks like there's a problem here: >where rating IN (1,2,3)") >while row = res.fetch_row do >row.collect! { |v| v.nil? ? "NULL" : v } >x=row[0] >b=row[1] >c=row[2] > ... >end Because you're in a loop with 'while row ... do', and then you're using the same variables for each row, ie: x, b, and c, this means that x, b and c will get redefined after every iteration of the loop. When the loop ends, x, b, and c will then be the last values for the last row. I think you'd be better off using Resultset#each_hash method, and then storing all the hashes in an array. a = [] res.each_hash do |h| a << h end Something like that, maybe? Hope this helps! -Luke -- Posted via http://www.ruby-forum.com/.