looking for a better way to query and cehck for overlapping timeframes.

am selecting records for display that has 3 fields of importance;
        date_time (unix timestamp)
        session_time (in seconds)
        user_id      (text field)

Of all the sessions recorded, we are looking for a count of duplicate sessions
for a given month. currently we are doing this with two seperate calls, but it
is taking forever to process;

# first query is to gather sessions that took place within a given month
$query = "SELECT * FROM logs WHERE name='$username' AND \
        date_time>$dategt AND date_time<$datelt \
        ORDER BY date_time DESC";
$result = pg_exec($database,$query);
        $row = pg_fetch_array($result,$count);
# as we go through the hits, check for duplicates within that timeframe as well
        $DUPquery = "SELECT session_id FROM logs WHERE name='$username' AND \
                date_time>$sessionstart AND \
                (date_time - session_time)<$datetime \
                ORDER BY name ASC, date_time DESC";

Obviously this is extremely processor intensive, not to mention it seems sloppy.
Any better recommendations, either on altering the above code, or another way to
get the information we require?


PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to