Both of the above are fine.
Or, if it is a good friend, say
I'm sorry to hear that you are having a difficult time, let me know if there's something that I can do for you.
I'm sorry to hear that, I have thought that there's somehting bothering you. I hope it gets better soon.
I'm sorry to hear that. Let's go out to have a nice lunch, my treat, maybe that will take your mind off things for a while.
I am not a teacher.
Student or Learner