FROM_UNIXTIME($since) OR updated > FROM_UNIXTIME($since) OR removed") or die("failed to create temporary table"); # purge entries marked for removal mysql_query("DELETE FROM note WHERE removed"); } $query = "SELECT DISTINCT id,note.sect,user,note,UNIX_TIMESTAMP(ts) AS ts,"; $query .= "IF(votes=0, 10, rating/votes) AS rate"; $query .= " FROM note"; if ($since) { $query .= ",updated WHERE note.sect=updated.sect AND NOT removed"; } else { $query .= " WHERE NOT removed"; } $query .= " ORDER BY sect,rate DESC,ts"; $res = mysql_query($query) or die("query failed"); while ($row = mysql_fetch_array($res)) { # get rid of the ordered fields, we just want the named ones. for ($i = count($row) / 2; $i >= 0; $i--) unset($row[$i]); echo "$row[id]|$row[sect]|$row[rate]|$row[ts]|$row[user]|", base64_encode(gzcompress($row[note],3)),"\n"; }