From: Douglas Seifert Date: 2012-08-11T03:56:33+09:00 Subject: Re: Help with database-related code pls --bcaec54ee62cebf53e04c6ede69d Content-Type: text/plain; charset=ISO-8859-1 Try rewriting the method like this to understand what is going on: def find_person puts "Enter name or ID of person to find:" idorname = gets.chomp #i would pronounce the variable as "ID or Name" # Get an array of people hashes that match the query conditions all_the_people = $db.execute("SELECT * FROM people WHERE name = ? OR id = ?", idorname, idorname.to_i) # Grab the first hash from the array. If the array is empty, #first will return nil person = all_the_people.first unless person puts "No result found" return end puts %Q{Name: #{person['name']} Job: #{person['job']} Gender: #{person['gender']} Age: #{person['age']}} end --bcaec54ee62cebf53e04c6ede69d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Try rewriting the method like this to understand what is going on:

=
def find_person
=A0 puts "Enter name or ID of person to find:"
=A0 idorname =3D gets.chomp =A0 =A0 = #i would pronounce the variable as "ID or=A0Name"

=A0 # Get an array of people hashes that match the query conditions
=A0= all_the_people =3D $db.execute("SELECT * FROM people WHERE name =3D ?= OR id =3D ?",=A0idornam= e, idorname.to_i)

=A0 # Grab the first hash from the array. =A0= If the array is empty, #first will return nil
=A0 person =3D all_the_people.f= irst

=A0 unless person
=A0 =A0 puts "No result found&q= uot;
=A0 =A0 return
=A0 end
=A0 puts %Q{Name: #{person['name= ']}
=A0 =A0 Job: #{person['job']= }
=A0 =A0 Gender: #{person['gender= ']}
=A0 =A0 Age: #{person['age']= }}

end
--bcaec54ee62cebf53e04c6ede69d--