Table structure and data are a good start.
It would be a better start if it would work. Your insert statements contain a syntax error which proves that you did not test them. Plese do not leave all your homework to others.
When you have corrected the error (probably only a typo), prepare the SQL query which you are unhappy with and present it in an repeatable form. Your query contains PHP variables which are not known to us. Of course it would not be hard to reconstruct them, but, as I said before, don't let us do your homework.
Wnen you have the query, please show us the query and the results and tell us why you are unhappy with them.