tags:

views:

15

answers:

2

I know how to get all Mysql Results from a table and output it with each_hash.do in Ruby like this

results = con.query "SELECT * FROM table"

#results.each_hash do |row|
  $url = row["Url"]
  $name = row["linkname"]
  $id = row["ID"]
  #end

But how can i get only one record extracted from results?

+1  A: 

You can use fetch_hash on the result.

e.g.

results = con.query "SELECT * FROM table"
record = results.fetch_hash
url = record["Url"]
# etc

There is also fetch_row which returns an array of the field values instead of a hash.

mikej
A: 

add a "limit 1" to your query?

rogerdpack