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!

Recommended Answers

All 2 Replies

Member Avatar for diafol

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.

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... :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.