Vars should be declared in the smallest scope they require and close to where they're first used.

$q->end_html should be part of the last output, not prior to your table output.

You should learn about the different methods of quoting so that you can reduce or eliminate the unnecessary escaping of the quotes.

Your connect statement should include an "or die" clause/statement because the RaiseError won't be in effect until after the successful connection. I see a semi-colon in that statement when it should be a colon.

You almost never want to do this: select * from

Instead, you should state which fields you want. It's not uncommon to alter the order of the fields in the db, which then alters order of the fields being selected when using select * from and that would introduce a bug in your script.

Since you're only selecting 3 fields, I'd specify those vars when fetching the data rather than using the @data array which you then use to copy the data.