require 'mysql'
#my = Mysql.new(hostname, username, password, databasename)
con = Mysql.new('localhost', '', '', 'student')
rs = con.query('select * from student')
rs.each_hash { |h| puts h['name']}
con.close
Tuesday, December 14, 2010
Wednesday, December 1, 2010
Delete elements in Hash
i=0
j=0
x=%w[a b c d e f g h]
y=%w[o p q r s t u v]
b=%w[a c e]
a={}
until j==x.length
a.store(x[j],y[j])
j+=1
end
until i==b.length
a.delete_if {|key,value| key==b[i]}
i+=1
end
a.each {|key,value| puts "#{key} #{value}"}
j=0
x=%w[a b c d e f g h]
y=%w[o p q r s t u v]
b=%w[a c e]
a={}
until j==x.length
a.store(x[j],y[j])
j+=1
end
until i==b.length
a.delete_if {|key,value| key==b[i]}
i+=1
end
a.each {|key,value| puts "#{key} #{value}"}
Subscribe to:
Comments (Atom)