If you ask people to talk about their favorite teacher (again) you will hear some common themes. Chances are, your favorite teacher is someone you liked and someone who liked you. Your favorite teacher was probably very helpful; perhaps very kind. You may have done very well in his/her class, or maybe you didn't. (Interesting how your "grade" in your favorite teacher's class doesn't seem to matter much.)
Good teachers understand the importance of good relationships with their students. When students feel comfortable to ask questions (and they are not embarrassed to be "wrong"), they tend to do much better in class--even if it is a subject that they don't particularly like.
So if you want to have good students, be a good teacher.