Yes, that's a good approach, although it is MySQL specific. If you ever change the DB, your code will probably break. Note an issue though, it's probably not going to happen :)
Just to answer your original question:
It doesn't work because you compare a UNIX timestamp to a MySQL Date field. Either you first format the $lastweek timestamp as SQL Date and then use it in the query, or you use FROM_UNIXTIME(timestamp) in your query (which is most likely MySQL only again).