if(isset($id)) { intval($id); $query = $DB_site->query("SELECT * FROM gallery WHERE id=$id"); while($iteminfo = $DB_site->fetch_array($query)) { // call your templates and stuff here } }