Add missing db select and change some db stuff to mysql_num_rows