Stax, 28 bytes
üÉ$♠═?S┼╪├8°‼←sí☼←T≡┴╜ô‼\↑0ⁿ
Unpacked, ungolfed, and commented, it looks like this.
"<table>"P print "table"
"<th>A"* "<th>A" repeated specified number of times
,D repeat the rest of the program specified number of times
"<tr>"p print "<tr>" with no newline
Q print top of stack without popping
.hd|t replace "h" with "d"