From: Phillip Gawlowski Date: 2007-03-26T22:53:19+09:00 Subject: Re: Ruby/MySQL SELECT results Paul Willis wrote: > Hi > > I am playing with Ruby/MySQL, I have everything installed ok. I can > INSERT into my database but I am having trouble with SELECT. > > I want to see if the text in the field 'title' has been used before and > if it has return the id of that row. If I run... > > require "mysql" > my = Mysql::new("hostname", "username", "password", "db") > hasid = my.query("SELECT id FROM table WHERE title = 'Here is a title'") > puts hasid > > I get a result like... > > # > > I am expecting just the number in the id field. Any ideas? hasid.each do |row| puts row end Keep in mind, that Ruby/MySQL doesn't "rewind" after using an iterator. I've circumvented that by doing the following: array = Array.new hasid.each do |row| array.push(row) end I haven't tested the code, but it mirrors the code I use, sans implementation details special to my program. -- Phillip "CynicalRyan" Gawlowski Rule of Open-Source Programming #9: Give me refactoring or give me death!