What is the difference between this two way and Which one is best? What do you suggest?
The difference is that you seperate the concerns in the second example. This means that you can change from database type (e.g. a SQL database, a XML file, an array, ect.) without changing to much code. In fact, you only create a new Model and you are ready!
Whether this is a good example of mvc? How can fix 2 example above for good mvc?
I think you mean that you want to know if this is correct MVC and, if not, how to change it. It is better to put all those logic (except the first line) inside a Model and call that specific method inside your controller. I have used CI once, so I can't help you with code examples...