0

I need to get the earliest date and the latest date in the below query. Not sure if the while loop is necessary to achieve this though? I don't need min/max for every tbl_type but the lowest of them all and the highest of them all.

        // get min and max date for all the table types
$tbl_types = array(1,7,8);

        foreach ($tbl_types as $tbl_type) {

            $sql  = "SELECT min(logdate) as min_date,max(logdate) as max_date FROM tbl_xxx";
            $sql .= " AND tbl_types_id = '".$tbl_type."'";
        $result = $this->query($sql);

        $item = array();
            while ($row = mysql_fetch_assoc($result)) {
                        array_push($item, $row);
                    }
        $return[]=$item;
        }

Cheers!

2
Contributors
2
Replies
18
Views
2 Years
Discussion Span
Last Post by adishardis
1

This code is mashed.

$tbl_types = array(1,7,8);
$tblString = implode(',',$tbl_types);
$sql = "SELECT min(logdate) as min_date, max(logdate) as max_date FROM tbl_xxx WHERE tbl_types_id IN ($tblString)";

I have no idea what you're trying to do after the query. Mind boggling.

0

haha i'm sorry i wasn't thinking straight... as you pointed out i dont need a foreach loop but only to use the IN operator.

forget this tread ever existed, i know I'll try... :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.