As an aside, be advised that the mysql extension is deprecated. You should switch to mysqli (note the i at the end) or PDO. I would personally recommend the latter.
One problem is that you set the rowspan value to be $mnum, which is the total number of rows you return from the query. What if you return five rows in total, the first two are the same and the next three are all different? You’ll have a rowspan=5 in there. You need a separate counter for the rowspan value which gets reset to 1 any time the date changes. Presumably your query sorts by date primarily?
In your example above, it performs the query which returns two rows. You then read the first row, see that the date in that row is different from the last seen date (because that’s still empty) and so you put “rowspan=2” in the button. You then read the second row, that’s got a different date as well, so then you put “rowspan=2” in that as well.
But, that’s not going to work properly. You want to draw the button at the end of the last row for a group of email addresses, but you’re drawing it at the end of the first row of a new email address, after you’ve drawn the first row with the new address. I’d say the logic needs to be something like:
get next record {
if (email != last-email) {
if (last-email != blank ) { // only do this if it's not the first time through
draw the button
reset the row coutner
} // end of if last-email not blank
} // end of if email has changed
draw record contents
} // end of get-next-record loop
draw button for final record
It’s a bit hard to be sure without being able to test it out. But “still not getting desired result” doesn’t help a lot - you need to show what result you’re getting, and why it’s not what you want, as you did earlier.
But the counter is updating incorrectly - you need to reset it when you draw the button, and increment it when you don’t draw the button. The times you are not drawing the button are the “extra” rows that you want to specify in your “rowspan” value, and without testing I also can quite figure out whether you want to be base one or zero.