<--?php // by teacher $hosts = 'and mediahostid in (108,11,126,134,180,203,209)'; //ttsb $hosts = 'and mediahostid in (165,170,226)'; // khaner $hosts = ''; // all db_set_active('artistworks'); $sql = "select mediaheaderid from media where mediatypeid=119 and isActive=1 $hosts group by mediaheaderid having count(*)>1"; print "sql: $sql

\n"; $result = db_query($sql); while ($row = db_fetch_object($result)) { $sql2 = "select mediaheaderid, m.id, fileName, m.inDate, mediahostid, hostURL from media m join mediaHost mh on mh.id=m.mediaHostID where mediaheaderid=$row->mediaheaderid and mediatypeid=119 and m.isActive=1 $hosts order by inDate"; print "sql2: $sql2
\n"; $result2 = db_query($sql2); $sql3 = ''; $lastFileName = ''; $idForFirstFilename = 0; while ($row2 = db_fetch_object($result2)) { print "
" . print_r($row2,true) . "
\n"; if (!$idForFirstFilename) $idForFirstFilename = $row2->id; if (!$sql3 && $lastFileName && ($lastFileName != $row2->fileName)) { $sql3 = "delete from media where mediaheaderid=$row->mediaheaderid and mediatypeid=119 and isActive=1 $hosts and id != $idForFirstFilename"; break; } $lastFileName = $row2->fileName; } print "$sql3

\n"; if ($sql3) $result3 = db_query($sql3); } ?>