This study examined difficulties middle school students have in learning mathematics and proposed a flipped classroom consisting of Khan Academy activities, small-group problem solving, and mathematical modeling to help improve their learning. A mixed-method approach was used to identify difficulties students have in learning mathematics, explore how the flipped classroom helped them reduce the learning difficulties identified, and examine if there were differences in students' mathematics achievement and their affective characteristics after participating in the flipped classroom. Qualitative analyses showed that students had difficulties in understanding mathematical concepts and finding effective ways to learn as well as negative views towards learning mathematics. This study also found that each activity of the flipped classroom had a different impact on student learning. Before class, the Khan Academy activities were most likely to help students understand mathematical concepts. In class, small-group problem solving activities were most helpful for students who had trouble finding effective learning methods and environments. Mathematical modeling activities were most likely effective in changing students' negative views towards mathematics. A quantitative analysis showed that the flipped classroom not only significantly improved the students' mathematics achievement, but also positively affected their confidence and motivation and how much they valued learning mathematics.