Okay, I think you're messed up on how many IDs can be declared inside of a document. An element ID is something that is unique throughout that document. So if you have an element with and ID of 1, there can only be that one element. Everything else must be something else. Classes can repeat, IDs can not.
In your second foreach you declare each table row to have an ID of value "mesajgur"+$i which if there is more than 1 item, will be the same for all of them. Unfortunately this can't happen. The one thing to do is to wrap those rows in a <div> element and apply that ID to the div. You could also use a table inside of that rows column and create however many rows you want in there, then just give the table the ID (or the row containing the inner table).
I'm sure it's clear as mud.... so any questions just ask....